On Sep 21, 2011, at 9:52 PM, Rodrigo Ruiz wrote:

Hi, I gotta make a model (telefone) that belongs to a person or to a
company, how do I do that?

Thank you,
Rodrigo

You probably want a polymophic association:

class Telefone < ActiveRecord::Base
  belongs_to :owner, :polymorphic => true
end

class Person < ActiveRecord::Base
  has_many :telefones, :as => :owner
end

class Company < ActiveRecord::Base
  has_many :telefones, :as => :owner
end

See the information at
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations

-Rob

Rob Biedenharn          
[email protected]     http://AgileConsultingLLC.com/
[email protected]               http://GaslightSoftware.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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to