dpal wrote in post #958568:
> Now there is also the fact that user has to know what they own.
> If I go with the
>
>  belongs_to :ownable, polymorphic => true.
>
> From user then user.ownable will either return company,
> real_state_company or natural user.

(I think you mean "real estate", not "real state".)


> I would have to do user.ownable_type to see which one and use a string
> comparisson.

Or user.ownable.class and use a class comparison.

Or better yet, do neither and use object polymorphism to automatically 
dispatch.  Remember, one of the nice things about OO development is that 
objects know how to respond to messages -- you often don't need 
conditionals.

>
> If I go the other route:
>
>   has_one :real_state_company
>   has_one :construction_company
>   has_one :natural_person
>
> I can say,
>
> if(user.construction_company != nil)
> {
>   company = user.company
>   redirect_to company
> }
> else if (user.real_state_company)
> {
> ....
> }

This isn't Java.  Lose the braces, parens, and "!= nil" and use "elsif" 
instead of "else if".

> etc.
>
> Which one is cleaner, better design ?

The polymorphic design.  It allows you to actually harness the object 
model to your advantage.

>
> Thanks
> -dan

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

-- 
Posted via http://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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to