On Sep 5, 2013, at 11:50 AM, Scott Ribe wrote:
> On Sep 5, 2013, at 9:47 AM, honey ruby <
emailtoh...@gmail.com> wrote:
>
>> Hi all
>>
>> I have two tables A and B
>> I have saved a record in table A and I want to save the id of that record in table B. How Can I do that.
>> Well I can do by search of same params which I save in Table A but I feel it is not that good approach.
>
> Just save it, then use the id ;-)
>
> Seriously, this is a very common idiom, and you'll find that rails takes care of it.
>
That would only be true in a create method, because the ID isn't known until after the thing is saved. But if your relationships are declared in the usual way (has_many, belongs_to, etc.) then this plumbing is taken care of for you in most cases.