records with todays date but those where the canceled_time is empty, the
above find selects all records for today also those records where the
canceled_time is not empty.
What is wrong here ?
Thanks for any hint.
Dani
--
Posted via http://www.ruby-forum.com/.
Have a look in log/development.log and see what query is being run.
Colin
>
> What is wrong here ?
>
> Thanks for any hint.
>
> 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 rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
class CourseDate < ActiveRecord::Base
has_many :course_lessons
end
CourseLesson
class CourseLesson < ActiveRecord::Base
belongs_to :course_date
end
so in the query:
@course = CourseDate.find_all_by_date_and_canceled_time(Date.today,nil)
'date' is in table 'course_dates'
'canceled_time' is in table 'course_lessons'
So the suggested:
CourseDate.where(:date => Date.today, :canceled_time => nil)
did not work (thanks Juan)
But I'm getting all records for today (and their related lessons),
eventhogh one of the records has its 'canceled_time' set with time. I'm
of course expecting to get only those records with 'canceled_time' not
set.
I'm using rails 3+
Colin, scope names looks elegant and I'll use it, but first I would like
to get my original query working.
Any hints how ?
Thanks
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