Update first table when data is created in the second table

Hi,

I want to know how to update data in first table when i create data in
second table.

For ex:

1)locations-Fields(id,name,reply_data)-TABLE ONE

2)Events-Fields(id,name)-TABLE TWO

I want to know how to update the reply_data column in the first table
when
data is added to the Events table.

this should work with callbacks like after_create or after_save:

just define them for table one and do whatever necessary with table two

Thorsten M. wrote:

this should work with callbacks like after_create or after_save:

ActiveRecord::Callbacks

just define them for table one and do whatever necessary with table two

Can u show me an example as to how to do it…

in the model of table two:

after_create :update_reply_data

def update_reply_data
@record = TableOne.find(…)
@record.update_attribute(:reply_data, new_value)
end

for:
TableOne.find(…)
must have some useful findcode, of course
and:
new_value should be the new value for reply_data,
whatever that is, can’t see that in your question

if the tables are related in some form, things get
more easy if you define this with belongs_to,
has_many and so on. but again i can’t guess those
details from your question

On Feb 6, 2008 9:28 PM, Koli K. [email protected]
wrote:

I want to know how to update the reply_data column in the first table
when
data is added to the Events table.

Add an after_save filter.

http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html#M001298


Greg D.
http://destiney.com/