Can I narrow down the type of classes retrieved by a Polymorphic relationship in Rails? -


I have a favored connection in the train, but in a special example of use, I want to get a record for only one

  class address & lt; ActiveRecord :: Base is_to: addressable ,: polymorphic = & gt; True end class person & lt; ActiveRecord :: Base has_many: Addresses ,: as in => : Addressable and Class Company & lt; ActiveRecord :: Base has_many: Addresses ,: as in => : Addressed End & gt; & Gt; C = Company.create (: name => "WidgetCo") & gt; & Gt; P = person.create (: name = & gt; "John Smith") & gt; & Gt; A1 = Address.create (: Street => "123 Foo ST",: city => "Barville",: state_code = & gt; "MT" ,: zip_code = & gt; "12345", addressable = & Gt; p)> & gt; & Gt; A2 = Address.create (: Road => "321 RD Contact" ,: City = & gt; "Buzzberg",: Statecode => "MT" ,: zip_code = & gt; "54321" ,: Addressable = & gt; c)> & gt; & Gt; Address (all: (terms = & gt; {: addressable_type = & gt; Person.class_name}) = & gt; [# & Lt; Address ID: 1, Street: "123 Foo ST" ... & gt;]  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -