⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

multiple db calls in update callback



ssfthurber

ssfthurber
  • profile picture
  • Member

Posted 04 June 2013 - 15:33 PM

instead of update in place my application requires versioning. so in the event of an update i need to end up with the old version of the record marked as expired and a new version inserted.  my thought was to use update callback to both insert the new record and update the old version marking it as expired.

all the callback examples show return with a single db call. is this a limitation or is there a way to code two db calls, as required by my use case?


davidoster

davidoster
  • profile picture
  • Member

Posted 04 June 2013 - 22:33 PM

I would use http://www.grocerycrud.com/documentation/options_functions/callback_before_update

and within this function I would do two things,

1. change the versioning field to mark this record as an older one and

2. with the same(previous) data insert a new record

 

The return is used when some (or all of the data) need to be altered before they are sent to the db, as it is in your case.

But at the same time you can do as many db calls within this callback. There is no limitation what you can do.


ssfthurber

ssfthurber
  • profile picture
  • Member

Posted 04 June 2013 - 23:06 PM

yes, this is the way to go. thanks.