Juan Pablo Avello wrote in post #1056480:
> El sbado, 14 de abril de 2012 13:12:19 UTC+2, Ruby-Forum.com User
> escribi:
>> class CourseLesson < ActiveRecord::Base
>> CourseDate.where(:date => Date.today, :canceled_time => nil)
>> to get my original query working.
>>
>> Any hints how ?
>>
>> Thanks
>>
>> Dani
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
> Certainly, that changes things a lot; find_by_* or where() constructed
> like
> this, expect all attributes used to be on the same table. If you need
> data
> from another table, you must join those tables in sql, so you need to
> add
> includes() or join() to your method chain.
>
> Using 'where', your query should look like:
>
> CourseDate.includes(:course_lessons).where(:date => Date.today,
> :course_lessons => { :cancelled_time => nil})
>
> or:
>
> CourseDate.includes(:course_lessons).where("course_dates.date = ? and
> course_lessons.cancelled_time is null", Date.today)
>
> Regards.

Hi Juan,
Thank you, both suggested queries are working fine !

But still I don't understand why my query is not working, I'm getting 
all lessons, so also without using include, through the association, 
rails knows to build the correct sql query, the only thing not working 
is, that also lessons with timestamp are selected. Why using 'nil' 
ignores the fact that timestamp is not 'nil' (as I'm expecting to select 
only those with
'cancelled_time' set to 'nil') ?

regards

Dani

-- 
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