Suavocado
Suavocado

Reputation: 969

Rails changing who the model "belongs_to" by changing which model ID is set

I have a slightly complicated model for my "attachments" that belongs to a "quote". I have a model "order" that could make use of this model but the attachments are separate. Can I have 2 "belong_to's" on the attachments and only set the id for 1? Is there a penalty to doing this over just creating an attachment model specifically for the order attachments?

Upvotes: 0

Views: 27

Answers (1)

dinomix
dinomix

Reputation: 976

I think what you are looking for is a polymorphic association.

http://guides.rubyonrails.org/association_basics.html#polymorphic-associations

Upvotes: 1

Related Questions