2009/9/24 Luis Enrique <[email protected]>:
>
> I am looking for a way to create , ( and this is the part I really do
> not know) a method a named_scope a something…
> that allows me to create an query where I can combine several columns
> from different tables.
> In plain sql I could create a view and work with it; but I like one of
> the concepts of named_scope that
> allows me to use it with other to form the query I want.
>
> I wish I could do something like this:
>
> class Master < ActiveRecord::Base
>  belongs_to :table1
>  belongs_to :table2
>  belongs_to :table3
>
>  named_scope :selected_fields, :select => "masters.col1, table1s.col3,
> talbe2s.col5"
> end
>s
> I've tried few things using joins and include but it seems like it is
> always selecting the Master table only.
> My playing around had not payed off at all, I’ve tried using :include,
> :select , etc…

Why do you wish to do this?  If it is for efficiency then are you sure
you need it?  You know that if you have a Master object @master then
you can say @master.col1, @master.table1.col3 and @master.table2.col5.
If in the find for @master you :include table1 and table2 it will do
it all in one query.

Colin

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to