EllisLab text mark
Advanced Search
2 of 31
2
   
DataMapper ORM v1.8.1
Posted: 09 June 2011 07:23 AM   [ # 21 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

I’m clueless. It doesn’t get any simpler than this. You don’t have a save() method in your model do you?

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 09 June 2011 09:46 AM   [ # 22 ]   [ Rating: 0 ]
Joined: 2011-05-30
18 posts

I found it .... -.-

Was a method inside my User-class which has validate as its name ..... now without it works.

Thanks for your help.

 
Posted: 09 June 2011 09:47 AM   [ # 23 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-15
147 posts

How would you save a data shared by a N:N relation?
Let me explain:
You have products and attributs for instance.
Products may have 1 or N attributs but Attributs could be used with 1:N products. If you had a sorting order you end with a value to be stored when saving the relationship.

class Product extends DataMapper {
    
    
public $has_many = Array('attribut');
class Attribut extends DataMapper {
    
    
public $has_many = Array('product');

When I create a new product I select the attributs I want to be part of the product. I also want to save some data such as value, sorting order or whatever. How would you recommand me to do this?
Create a another model that will have many product and attribut? Example :

class Product extends DataMapper {
    
    
public $has_many = Array('product_attribut_detail');
}
//------------------------
class Product_attribut_detail extends DataMapper {
    
    
public $has_one = Array('product''attribut');
}
//------------------------
class Attribut extends DataMapper {
    
    
public $has_many = Array('product_attribut_detail');
 
Posted: 09 June 2011 11:10 AM   [ # 24 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts
benboi - 09 June 2011 01:46 PM

Was a method inside my User-class which has validate as its name ..... now without it works.

I should have spotted that. wink

Yes, you have to be careful overloading Datamapper methods. The list of reserved names can be found here.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 09 June 2011 11:16 AM   [ # 25 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

@Spir,

If I understand you correctly:

You have models called Product and Attribut, in an N:M relation. They will have a $has_many to oneanother. You will need a relationship table connecting the two, called Attributs_Products, containing 3 fields: ‘id’, ‘attribut_id’ and ‘product_id’. This relationship table doesn’t need a model. So your first code block is correct.

You make relations by loading the required objects, and then link them:

// get a product and an attribute
$product = new Product(1);
$attribut = new Attribut(1);

// relate the two
$product->save($attribut);

// get all attributes
$attribut->get();

// relate all of them to the product
$product->save($attribut->all); 

If you have values that don’t belong to product or attribute, but are part of the relation, you need to add these fields to the Attributs_Products table. Use the Datamapper join_fields methods to manipulate them. See the manual for some examples.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 09 June 2011 11:37 AM   [ # 26 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-15
147 posts

Yes I first set correctly as you said and it worked but then I wanted to add some fields to that relation. I’ll check about the join_fields. That’s exaclty what I’m looking for!
Thanks a million WanWizard for your help!

 
Posted: 09 June 2011 08:42 PM   [ # 27 ]   [ Rating: 0 ]
Avatar
Joined: 2011-01-30
454 posts
WanWizard - 08 June 2011 05:35 PM

Sorry for the late response, I’ve been hidding in a corner feeling very ashamed…  sick

Bug (and two more introduced in the same set of changes) have been fixed. Code on bitbucket, and the downloads, have been updated.

Joining us basketcases are you?  tongue laugh

 Signature 

This is the wonderful logo InsiteFX did for me. I had to scale it for this site. But his work is worth showing off.

 
Posted: 09 June 2011 10:45 PM   [ # 28 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-06
65 posts

First thanks for the updates… include_related many to many made my life easy…

Now for my BIG question. using get_paged… I want to do something similar to CI standard pagination.

e.g. << < 1 2 3 4 > >>

I’ve got the prev/next code working fine.

Suggestions?

Thanks,
Brendan

 Signature 

Brendan Rehman,
Freelance CI and Web Application Developer
http://www.ignitedcoder.com
Sweet Tweets:http://twitter.com/#!/IgnitedCoder

 
Posted: 10 June 2011 03:41 AM   [ # 29 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

Not exactly sure what your question is.

If you have a page number, and you’ve made up your mind how many rows on a page, get_paged() will give you all information you need. Just create a view partial that generates the table structure and the pagination under it, using the information from $object->paged, as described here: http://datamapper.wanwizard.eu/pages/getalt.html#get_paged.

You can also feed CI’s pagination with the information from get_paged(), but you’ll have to convert pages to rownumbers, as Pagination works with a row offset, and not a page number. Which can be akward, since the user can type any number in the URL, which could be a row outside the scope, or halfway on a page…

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 10 June 2011 06:05 AM   [ # 30 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-06
65 posts

Apologies if I wasn’t to clear with my question…

Basically I want to grab the page numbers as follows:

Assuming I have 10 pages of data and I’m showing records per page.

I can easily do Prev / Next using the documents options but what I’d like to do is display the page numbers as well as in:

Prev 1 2 3 4 Next - so when a user select page 4 the page numbers change to
Prev 4 5 6 7 Next - Everything else is working great already. I can of course calculate this base on total page count and current page but it would be nice if the $paged object calculates it for me just like setting CI std pagination options i.e. $config[‘num_links’] = 2; will produce Prev 1 2 Next.

Hope this makes more sense…

PS

F#$%@ awesome “excuse the french smile” library I can’t even remember when I last used AR. I hope your lib ends up in reactor as a standard. I’ve been using it in production apps without issue, in fact with nginx setup it performs very well in all of my tests and when the tables are properly indexed it can handle anything I’ve thrown at it.

Brendan

 Signature 

Brendan Rehman,
Freelance CI and Web Application Developer
http://www.ignitedcoder.com
Sweet Tweets:http://twitter.com/#!/IgnitedCoder

 
Posted: 10 June 2011 12:54 PM   [ # 31 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

You can do that with CI’s standard pagination class. It will produce exactly that.

You only need to do some calculations, because pagination works with record numbers, while get_paged() works with pagenumbers.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 11 June 2011 07:34 AM   [ # 32 ]   [ Rating: 0 ]
Joined: 2011-06-11
2 posts

in DMZ_VERSION 1.8.1 i found some mistake.

1. public function group_start($not = ‘’, $type = ‘AND ‘){
....

$this->_where_group_started TRUE; (miss line

return $this;
}

2. public function group_end(){
...

return $this; (miss line

}

 
Posted: 11 June 2011 07:39 AM   [ # 33 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

This has been fixed a few days ago, please download the latest zip…

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 13 June 2011 07:03 AM   [ # 34 ]   [ Rating: 0 ]
Avatar
Joined: 2009-11-10
24 posts

Is there any way make method “droop_down” in datamapper class, because I need it (and I think others to ) very often for select fields,

 
Posted: 13 June 2011 07:11 AM   [ # 35 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

No, there isn’t.

Datamapper provides the basic methods to interact with your database, the rest is up to you. Add a method to your model that returns an array that you could use in your views.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
2 of 31
2