Ruby on Rails
Sunday, August 12, 2018
On Saturday, February 3, 2018 at 5:49:13 PM UTC-5, Walter Lee Davis wrote:
> On Feb 3, 2018, at 3:56 PM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Friday, January 12, 2018 at 7:06:12 PM UTC-5, fugee ohu wrote:
> Let's say I have a table of products and a table of accessories Each accessory can have many products that it's compatible with while each product has many accessories available for it It In the problem I'm trying to solve accessories cannot belong to products and products cannot belong to accessories So, unless I was to create a third table with fields for product_id and accessory_id, how could I allow each to have many of the other Do I have to create the third table? Thanks in advance
>
> @person.pictures << @picture tries to, create a new picture, not add it to the person_picture association table
Where does @picture come from? Did you build it in memory, or load it from the database? Rather than adding an object you created to an association, try building the associated object from the beginning, like this:
@picture = @person.pictures.build(picture_attributes)
Now that picture is automatically in the @person.pictures association, and has whatever other attributes you assigned to it.
When you save the picture, the corresponding person_picture instance will be persisted as well. The picture has to be created and saved before the person_picture record can be, otherwise where would the person_picture.picture_id value come from?
Walter
Can we revisit this one I'm doing a family tree and trying to manage spousal relationships so i have person has_many people through: :partnerships But now partnerships can't have person_id twice so this is perplexing me
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/2339c6e7-585a-4239-9b07-aba325913e96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment