wyginwys
(Wyginwys)
1
Hi
I have setup a MANY_MANY relation at last and now I need to save the related model.
I see there are some extensions (save-relations-ar-behavior, esaverelatedbehavior etc)
which does this job. I want to use a more recent one.
Could you recommend one for me?
I can wholeheartly recommend the with-related-behavior 
wyginwys
(Wyginwys)
3
Thanks for pointing out the extension and the site which I wasnt aware of.
I am trying to save a Post with Categories using table tbl_post_categories as described in the definitive guide.
In tbl_post_categories I have two primary keys, postid,categoryid which are also foreign keys referencing Post and Category
tables.
I have MANY_MANY relations defined in both models Post, Category against each other and also
I have HAS_MANY relations pointing to tbl_post_categories table in both.
and I have BELONGS_TO relations in tbl_post_categories pointing Post and Category tables.
How should I use WithRelatedBehaviour in this case?
I am getting
Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
errors on my tries.
The error is straightforward because there is no corresponding key in the referencing table.
But How can I save a tbl_post_category model without knowing its postid?
hastenax
(V Galyanin)
4
You can also try github.com/hastenax/yii-cmanymanyactiverecord without any db constraints.