Hello,

I want to add a Partner property to more than one type of models (ie.
SalesOrder and PurchaseOrder).
Is this the proper way of defining associatons or there's a simpler
way?

class Partner < ActiveRecord::Base
has_many :sales_orders
has_many :purchase_orders
end

class SalesOrder < ActiveRecord::Base
belongs_to :partner
end

class PurchaseOrder < ActiveRecord::Base
belongs_to :partner
end

Thanks

Zoltan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Robert Walker at Mar 31, 2012 at 7:44 pm

    "Zoltán Iklódi" <ziklodi@gmail.com> wrote in post #1054400:
    Hello,

    I want to add a Partner property to more than one type of models (ie.
    SalesOrder and PurchaseOrder).
    Is this the proper way of defining associatons or there's a simpler
    way?
    What you need here is a polymorphic association. See:

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

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 31, '12 at 6:46p
activeMar 31, '12 at 7:44p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Robert Walker: 1 post Zoltán Iklódi: 1 post

People

Translate

site design / logo © 2021 Grokbase