thank you
On Thu, Sep 22, 2011 at 12:43 AM, Rob Biedenharn
<Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>
wrote:>
> 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
> Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
http://AgileConsultingLLC.com/
> rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
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.