how do i add rows to the associations table in a has_many_through relation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how do i add rows to the associations table in a has_many_through relation

fugee ohu
how do i add rows to the associations table in a has_many_through relation

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/47cab85e-cb43-483b-b16b-453880c44ca0%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: how do i add rows to the associations table in a has_many_through relation

Ariel Juodziukynas
Following the example models from the guide https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association you would do something like:

@physician.appointments.create(patient: @patient)


El sáb., 5 oct. 2019 a las 19:19, fugee ohu (<[hidden email]>) escribió:
how do i add rows to the associations table in a has_many_through relation

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/47cab85e-cb43-483b-b16b-453880c44ca0%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcCwzk_qhxwXoFx6UzsYVDGqjo4abZCmiWi2qhESkqOMug%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: how do i add rows to the associations table in a has_many_through relation

Ariel Juodziukynas
I think you can actually do @physician.patients << @patient on some cases where your join model does not require anything else, but in that case it's more common to use a has_and_belongs_to_many association instead, if you use a has_many :through you usually want more data on the join model so you need to use the code on the previous response

El dom., 6 oct. 2019 a las 0:33, Ariel Juodziukynas (<[hidden email]>) escribió:
Following the example models from the guide https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association you would do something like:

@physician.appointments.create(patient: @patient)


El sáb., 5 oct. 2019 a las 19:19, fugee ohu (<[hidden email]>) escribió:
how do i add rows to the associations table in a has_many_through relation

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/47cab85e-cb43-483b-b16b-453880c44ca0%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcBhtqd5RjneK0bgD3vktJObNh24LR1r9Uh3FS2H0obRHQ%40mail.gmail.com.