Andrius Chamentauskas wrote:
> Well first of all are you 100% sure you need OnMarketDateDimension and
> SaleDateDimension classes? If you don't have any custom logic in them
> you should probably remove them and change associations a bit:
> class SalesFact < ActiveRecord::Base
>   ...
>   belongs_to :on_market_date_dimension, :class_name =>
> 'DateDimension', :foreign_key => 'on_market_date_dimension_id'
>   belongs_to :sale_date_dimension, :class_name =>
> 'DateDimension', :foreign_key => 'sale_date_dimension_id'
> end
> 
> And I see no reason why you can't just do: SalesFact.first :include =>
> [:on_market_date_dimension, :sale_date_dimension]. Or did I
> misinterpret what you need?

Andrius: I your solution is very close.  I agree that it does not make 
sense to create OnMarketDateDimension and SalesDateDimension classes (or 
sql views onto a table, as I was suggesting).  I've knocked together a 
project implementing your approach, but I haven't grok'ed how to make a 
query -- maybe you can help.

If I try this:

SalesFact.first(:include => [:on_market_date_dimension, 
:sale_date_dimension])

I get an un-embellished SalesFact, which doesn't do me much good -- I'd 
like join with the two dates to which it refers.  If I try the same 
thing with a :select:

SalesFact.first(:select => 'sales_facts.*, on_market_date_dimensions.*, 
sale_date_dimensions.*', :include => [:on_market_date_dimension, 
:sale_date_dimension])

I get an SQL error because Rails is generating a query based on 
"sales_fact.id", which we intentionally suppressed in the schema (:id => 
false).

So my question: Given a SalesFact (or a group of SalesFacts), what's the 
AR.find() syntax for a query that does a join against 
:on_market_date_dimension and :sale_date_dimension?

Thanks in advance...
-- 
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 [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