Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.1
#21

[eluser]benboi[/eluser]
Code:
$bla = new User();
                $bla->name = 'foo';
                $bla->save();
                
                var_dump($bla->check_last_query());


Quote:SELECT *
FROM (`user`)
WHERE `user`.`username` = ''

string(63) "

SELECT *
FROM (`user`)
WHERE `user`.`username` = ''

"
#22

[eluser]WanWizard[/eluser]
I'm clueless. It doesn't get any simpler than this. You don't have a save() method in your model do you?
#23

[eluser]benboi[/eluser]
I found it .... -.-

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

Thanks for your help.
#24

[eluser]Spir[/eluser]
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.

Code:
class Product extends DataMapper {
    
    public $has_many = Array('attribut');
}
Code:
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 :
Code:
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');
}
#25

[eluser]WanWizard[/eluser]
[quote author="benboi" date="1307641589"]Was a method inside my User-class which has validate as its name ..... now without it works.[/quote]
I should have spotted that. Wink

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

[eluser]WanWizard[/eluser]
@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:
Code:
// 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.
#27

[eluser]Spir[/eluser]
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!
#28

[eluser]Basketcasesoftware[/eluser]
[quote author="WanWizard" date="1307568923"]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.[/quote]
Joining us basketcases are you? :-P
#29

[eluser]IgnitedCoder[/eluser]
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
#30

[eluser]WanWizard[/eluser]
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/get...#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...




Theme © iAndrew 2016 - Forum software by © MyBB