Christian Fazzini | 7 Sep 16:34
Picon

Re: Polymorphic advice for this design

Ar, your solution is not very clear. Can you also indicate columns and
migration file

On Sep 7, 9:42 pm, Ar Chron <li...@...> wrote:
> I'd be less worried about the columns, but more focused on the entities
> involved...
>
> Your 'suggestion' seems to be analogous to a 'contact', and a contact
> may well be tied to a business and/or a city (business leaders often sit
> on local/city councils/chambers/whatever they are called - sometimes
> with separate phone/address/email, sometimes not).
>
> So I could perhaps see:
>
> Business
>   has_many :suggestionlinks, :as =>  :sugglinkable
>   has_many :suggestions, :through => :suggestionlinks
>
> City
>   has_many :suggestionlinks, :as => :sugglinkable
>   has_many :suggestions, :through => :suggestionlinks
>
> Suggestion
>   has_many :suggestionlinks
>   has_many :businesses, :through => :suggestionlinks,  :source =>
> :business, :conditions => "suggestionlink.sugglinkable_type =
> 'Business'"
>   has_many :cities, :through => :suggestionlinks, :source => :city,
> :conditions => "suggestionlink.sugglinkable_type = 'City'"
>
> Suggestionlink
>   # id INT
>   # suggestion_id INT
>   # sugglinkable_type VARCHAR()
>   # sugglinkable_id INT
>   belongs_to :suggestion
>   belongs_to :sugglinkable, :polymorphic => true
>   belongs_to :business, :class_name => 'Business', :foreign_key =>
> 'sugglinkable_id'
>   belongs_to :city, :class_name => 'City', :foreign_key =>
> 'sugglinkable_id'
>
> Or something like that
> --
> Posted viahttp://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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Gmane