Model that belongs to Person or Company

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

Thank you,
Rodrigo

On Sep 21, 2011, at 9:52 PM, Rodrigo R. 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

-Rob

Rob B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/

thank you

On Thu, Sep 22, 2011 at 12:43 AM, Rob B.