Page 1 of 1

Duplicate a record & related records in another table

PostPosted: Thu Mar 17, 2011 12:30 pm
by semicon_guy
I am trying to figure out a way to duplicate an existing record in Xataface, and -also- duplicate the related records that are described in relationships.ini.

For example, if I have two tables:
1) People (PersonID, Name)
2) Tasks (TaskID, PersonID, Task)
i.e. each person has multiple tasks

I would like to be able to duplicate a person and at the same time ALSO duplicate all of their associated tasks. Does Xataface include a way to do this functionality, with a trigger or something? The follow up question would be whether it supports duplicating files as well (that are on the filesystem and not a BLOB).

Thanks!

Re: Duplicate a record & related records in another table

PostPosted: Thu Mar 17, 2011 12:40 pm
by shannah
You would need a custom action to do this. The xataface copy records action doesn't deal with any relationships because it gets quite complex (some relationships need to point at the same record - some need to point at a duplicate record).

-Steve

Re: Duplicate a record & related records in another table

PostPosted: Thu Mar 17, 2011 1:50 pm
by shannah
I suppose we could add an afterCopy() hook for the delegate class so that this method would be called after a record is copied and you can add your custom relationship copies in that method... This would be pretty easy to add.

Re: Duplicate a record & related records in another table

PostPosted: Thu Mar 17, 2011 2:12 pm
by shannah
I have added the beforeCopy and afterCopy hooks in SVN. Here is the wiki page that describes the afterCopy hook:
http://xataface.com/wiki/afterCopy

You can add support for this by updating your copy of Dataface/CopyTool.php to the version in SVN:
http://weblite.ca/svn/dataface/core/tru ... pyTool.php

-Steve

Re: Duplicate a record & related records in another table

PostPosted: Mon Mar 21, 2011 12:32 pm
by semicon_guy
Thanks for adding this feature. I will hopefully try it out soon and let you know!