Page 1 of 1

Saving related records

PostPosted: Fri Mar 25, 2011 7:06 am
by jay
Hi.

Is there a way to store the related records of a relationship at once? E.g.: if I have a University class and a university can have many faculties, is it possible to do something like this?:
$uni = new Dataface_Record('universities', array(...));
$uni->save();
$uni->save_related('faculties', array-of-faculties);

It would be nice to have a function that deletes the faculties that are no longer in the relationship, update the ones that changed and insert the new ones.
The framework is pretty nice, but maybe that's asking too much... :)


J.

Re: Saving related records

PostPosted: Fri Mar 25, 2011 10:44 am
by shannah
There is no function like this right now although there are places in the Xataface framework where similar things are done. E.g. Dataface/IO.php handles the saving of records and it handles special cases for transient fields containing related records (e.g. for the grid widget and checkbox group widgets) -- the implementation of this currently is a bit of a hack (it actually checks for specific widget types... and this shouldn't be necessary in a perfect world).

The Dataface_IO class includes methods that could be used as parts of such a function:
addRelatedRecord
removeRelatedRecord
addExistingRelatedRecord

-Steve