Koli Koli
2008-Feb-07 03:28 UTC
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2008-Feb-07 10:34 UTC
Re: Update first table when data is created in the second ta
this should work with callbacks like after_create or after_save: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html just define them for table one and do whatever necessary with table two -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Koli Koli
2008-Feb-07 14:37 UTC
Re: Update first table when data is created in the second ta
Thorsten Mueller wrote:> this should work with callbacks like after_create or after_save: > > http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html > > just define them for table one and do whatever necessary with table twoCan u show me an example as to how to do it.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2008-Feb-07 15:21 UTC
Re: Update first table when data is created in the second ta
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald
2008-Feb-12 22:28 UTC
Re: Update first table when data is created in the second table
On Feb 6, 2008 9:28 PM, Koli Koli <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---