You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I wanted to use a many-to-many relation in Symfony 1.4, I got the advice at StackOverflow (http://stackoverflow.com/questions/10911261/many-to-many-relation-on-same-table) to update to the newest sfPropelORMPlugin, as I did.
With the new version, Propel did recognize the many-to-many relation correctly, however, I still got an error while saving (only when a relation is made):
Unable to execute INSERT statement [INSERT INTO `item_has_item` (`ITEM_ID`) VALUES (:p0)]
[wrapped: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a
child row: a foreign key constraint fails (`SI/item_has_item`, CONSTRAINT
`item_has_item_FK_1` FOREIGN KEY (`parent_item_id`) REFERENCES `item` (`id`))]
I have found, after a long extensive search, that the form generator fails to correctly understand the many-to-many relation on the same table. In the function saveItemHasItemList($con = null):
$c = new Criteria();
$c->add(ItemHasItemPeer::ITEM_ID, $this->object->getPrimaryKey());
ItemHasItemPeer::doDelete($c, $con);
$values = $this->getValue('item_has_item_list');
if (is_array($values))
{
foreach ($values as $value)
{
$obj = new ItemHasItem();
$obj->setItemId($this->object->getPrimaryKey());
$obj->setItemId($value);
$obj->save();
}
}
As you can see, the ItemId is twice set, while the ParentItemId is not set, hence the constraint value. It should be generated as:
This solves the saving problem, however, it still does not show the already selected relations. To solve that, you should also change the updateDefaultsFromObject():
foreach ($this->object->getItemHasItemsRelatedByItemId() as $obj)
Should be:
foreach ($this->object->getItemHasItemsRelatedByParentItemId() as $obj)
Conclusion: Propel fails to correctly build the form class of a many-to-many relation on the same table.
The text was updated successfully, but these errors were encountered:
I wouldn't know: I've stopped using Propel ever since we've moved to Symfony 2.x and Doctrine. Since this plugin is for SF1.x which is no longer supported, I do not think it will be solved.
As I wanted to use a many-to-many relation in Symfony 1.4, I got the advice at StackOverflow (http://stackoverflow.com/questions/10911261/many-to-many-relation-on-same-table) to update to the newest sfPropelORMPlugin, as I did.
With the new version, Propel did recognize the many-to-many relation correctly, however, I still got an error while saving (only when a relation is made):
My schema.yml:
I have found, after a long extensive search, that the form generator fails to correctly understand the many-to-many relation on the same table. In the function saveItemHasItemList($con = null):
As you can see, the ItemId is twice set, while the ParentItemId is not set, hence the constraint value. It should be generated as:
&&
This solves the saving problem, however, it still does not show the already selected relations. To solve that, you should also change the updateDefaultsFromObject():
Should be:
Conclusion: Propel fails to correctly build the form class of a many-to-many relation on the same table.
The text was updated successfully, but these errors were encountered: