Re: SaveAll weird behavior

2010-07-12 Thread Jon Bennett
Hi,

> i have and app with 3 models, associated in this way
>
> class Item extends AppModel {
>        var $name = "Item";
>        var $belongsTo = array("Category");
>        var $hasMany = array(
>                "Fathers" => array(
>                        "className" => "Relationship",
>                        "foreignKey" => "child_id"
>                ),
>                "Childrens" => array(
>                        "className" => "Relationship",
>                        "foreignKey" => "father_id"
>                )
>        );
>        var $hasAndBelongsToMany = array("Colour");
> }
>
> Note that "Fathers" and "Childrens" are pointing to the same model
> ("Relationship").
>
> now...
>
> if i try to edit one of my items, with a Father relationship set. the
> data won't update.
> if i remove any father relationship my edit action will work properly.

You may have more luck if you set up an additional Relationship
association (you can use contain to not include it in finds later on),
and then have the condition that denotes whether it's a Father or
Child in the form, eg:

echo $this->Form->input('Relationship.0.id');
echo $this->Form->input('Relationship.0.name');
echo $this->Form->hidden('Relationship.0.type',
array('value'=>RelationShipTypeFather);

echo $this->Form->input('Relationship.1.id');
echo $this->Form->input('Relationship.1.name');
echo $this->Form->hidden('Relationship.1.type',
array('value'=>RelationShipTypeChild);

Cheers,

Jon

-- 
jon bennett - www.jben.net - blog.jben.net

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


SaveAll weird behavior

2010-07-12 Thread Ernesto
Hello.

i have and app with 3 models, associated in this way

class Item extends AppModel {
var $name = "Item";
var $belongsTo = array("Category");
var $hasMany = array(
"Fathers" => array(
"className" => "Relationship",
"foreignKey" => "child_id"
),
"Childrens" => array(
"className" => "Relationship",
"foreignKey" => "father_id"
)
);
var $hasAndBelongsToMany = array("Colour");
}

Note that "Fathers" and "Childrens" are pointing to the same model
("Relationship").

now...

if i try to edit one of my items, with a Father relationship set. the
data won't update.
if i remove any father relationship my edit action will work properly.

i PRed the data in Item::beforeSave and everything looks ok.

any advice?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en