Ruby on Rails
Thursday, September 5, 2013
Thanks for the response Colin my last mail was deleted some how anyway thanks for your reply. So If I use association between the tables
Table A Table Bnow I save a new record to A
@table_a = TableA.save
@table_b = ?
what should be my next line so that id of that saved record will save in Table B
And how should we approach this with out association if there is no rails only Ruby project
help me on this
On Thu, Sep 5, 2013 at 10:07 PM, Colin Law <clanlaw@googlemail.com> wrote:
On 5 September 2013 17:12, honey ruby <emailtohoneyruby@gmail.com> wrote:As I suggested a little while ago when you first asked this question,
> Thanks for your quick responses. Does I get the same id if I use
> @whatever.reload.
> if that model is accessed often and there are multiple users working on same
> model and I want table A id to be saved as new record in table B
> Table A
> id name email
> 878 Sam sam@mail.in.com
>
>
> as I save 878 record in Table A I want that 878 id to be saved as new record
> in table B
> Table B
> id table_a_id
> 900 878
but did not reply to my response, you should consider doing this using
an association between the tables. Something like table_b belongs_to
table_a, table_a has_many table_bs. Then rails will do a lot of the
hard work for you. Almost always in rails if you are manipulating id
values then you are doing it wrong.
Colin
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs7jwBTiOh4dWLCrDEjDQOdfLceSYf9NY1qoTST8f%3DcqA%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAOKUzCknCfEBTsiddykGqCb4K_goTpbG53bG%3DYuJFY75FHKx9A%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment