Forum: Ruby on Rails find with add of an atttributes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Luca R. (Guest)
on 2008-12-06 20:34
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
Mark Reginald J. (Guest)
on 2008-12-10 05:18
(Received via mailing list)
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
This topic is locked and can not be replied to.