Find with add of an atttributes


#1

I have wrote this:
EventDate.find(:all,
:include => [:container,{:event =>
[:photo,:event_type_names]},{:place=>:location}],
:joins =>" RIGHT JOIN (SELECT
event_dates.id,date_add(event_dates.date, INTERVAL i DAY ) AS date
FROM (select 0 as i union all select 0 union all select 1
union all select 2) as integers CROSS JOIN event_dates
WHERE i<= number_days AND (event_dates.days_of_week=‘8’
OR concat(’%’,event_dates.days_of_week,’%’) like
concat(’%’,DATE_FORMAT(date_add( event_dates.date, INTERVAL i DAY
),’%w’),’%’))
ORDER BY date LIMIT 0,40) as date_days ON date_days.id=event_dates.id
",
:order=>“date_days.date”

I want select also the date_days.date attribute.
Is there any mode to do it?
thanks


#2

Luca R. wrote:

concat(’%’,DATE_FORMAT(date_add( event_dates.date, INTERVAL i DAY
),’%w’),’%’))
ORDER BY date LIMIT 0,40) as date_days ON date_days.id=event_dates.id
",
:order=>“date_days.date”

I want select also the date_days.date attribute.
Is there any mode to do it?

All the date_days fields will be selected by default,
the “date” field being available in each result as
event_date[:date].

You’re in trouble if this conflicts with an EventDate
attribute, because Active Records has ignored the
find :select option when eager loading is used (though
I’m not sure whether this is still the case for Rails 2.2).
A patch is available for Rails 2.0.2 that allows :select
to be used in these circumstances.

Are you sure you want to use a right join? This could
give Active Record trouble.


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com