HOWTO: Find what the value of a relationship fields was before they were changed in a logic hook

bsoremsugar —  April 18, 2012 — 2 Comments

Came across this post in the forums the other day:

I have a one-to-many relationship between a custom module and Contacts. I’ve added a before_save logic hook to the custom module, and I need to be able to check if the related Contact has changed. For all other fields, I can accomplish this by comparing $bean->fieldname to $bean->fetched_row['fieldname']. However, the relationship id value (my_modulecontacts_ida) does not appear in the fetched_row array. I have a value for $bean->my_modulecontacts_ida, but there is no $bean->fetched_row['my_modulecontacts_ida'], so the two are never equal. How can I fetch the old value of my_modulecontacts_ida?

The poster is right here; $bean->fetched_row only contains the fields on the primary module record itself, and doesn’t handle those in related fields. But as poster shyam007 points out, you can look in the $bean->rel_fields_before_value array instead for these. Hopefully this tip helps other’s struggling for a way to do this.

2 responses to HOWTO: Find what the value of a relationship fields was before they were changed in a logic hook

  1. 

    Great post as always. Very informative and helpfull. I heave learned more from your blog then all others combined. 

  2. 

    I heave learned more from your blog then all others combined.
    biltek akademi bilgisayar kursu autocad kursu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s