Insert row in one table and after save I want that Id in another table to be saved

12 views
Skip to first unread message

honey ruby

unread,
Aug 30, 2013, 4:00:14 AM8/30/13
to rubyonra...@googlegroups.com
Hi all

There is a scenario with 2 tables.
I will insert the one row in table 1 and after I save my row in table one I want that Id to be saved in another table immediately how to approach this scenario.
kindly help  me




Regards,
Honey 

Colin Law

unread,
Aug 30, 2013, 4:13:31 AM8/30/13
to rubyonra...@googlegroups.com
On 30 August 2013 09:00, honey ruby <emailtoh...@gmail.com> wrote:
> Hi all
>
> There is a scenario with 2 tables.
> I will insert the one row in table 1 and after I save my row in table one I
> want that Id to be saved in another table immediately how to approach this
> scenario.

Which bit don't you know how to do?
Where to put the code?
How to determine the id of the row?
How to find the record in the second table?
How to change the value in the second table?
How to save the value in the second table?
Something else?

But before that the more important question is whether you should have
a belongs_to, has_many (or similar) association between the tables so
that rails will do most of the work for you.

Colin
Reply all
Reply to author
Forward
0 new messages