I'm wondering something... If i have an Orm object with has many and do something like this :
$mySuperObject->myHasManyRelations = null;
$mySuperObject->myHasManyRelation = // set new relations here
The previous objects, no longer used, still exists in database, just with the foreign key set to null.
I want them deleted instead... i took a look in hasmany.php line 224, with the comment "// if any original ids are left over in the array, they're no longer related - break them"
Are there some way i don't see to simply delete old related ?
If you're talking about related method in query, it does, like this : $mySuperObject = Model_MySuperObject::query->related('myHasManyRelations') // end of query
Edit : The Orm know witch are new, because it set the foreign key to null only for the olds relation. What i want is delete them instead of just break relation
That doesn't execute anything, unless you add a get() to it.
I meant the ORM is only aware of relations loaded from the database, it doesn't know what's in the database if you haven't queried it.
There is a difference between deleting the relation, and deleting the related record(s). When you unset a relation, you delete the relation, not the related record. It just disconnect it, as you have observed.
If you want to delete them, either call delete() on the related object, or define the relation as 'cascade_delete' => true if you always want to delete instead of disconnect.
Well, sorry, i should have been more clear : It's the Grouppermission and Rolepermission from the auth package. When changing the permission, the old data can be deleted from those table, but i will do it manually i guess.
At this time, it's just let your sql table with a lot of completly useless record with foreign key set to null. An observer for those classes, deleting olds permissions, would be great. It's planned ?
There is a many to many relation between Role and Permission, and between Group and Permission, which uses Grouppermission and Rolepermission as join table.
So when you disconnect a permission, you have to use role->permission or group->permission. It will delete the join table record if you do (which is a feature of the many-many). You only need to access the join table relation (or record) directly if you want to set a custom action selection on a specific relation.