Forum: Ruby on Rails ActiveRecord problems from within template

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dorian M. (Guest)
on 2006-05-18 09:04
(Received via mailing list)
my Film model has this:

  has_many                :live_action_personnel,
                          :class_name => "Credit",
                          :include => :credit_type,
                          :order => 'credit_types.position,
credits.position ASC',
                          :group => 'credit_types.personnel_type',
                          :conditions =>

If I try and test this for emptiness:
if @film.live_action_personnel.size > 0
I get the following error:

MysqlError: Unknown table 'credit_types' in where clause: SELECT
count(*) AS count_all FROM credits WHERE (credits.film_id = 16 AND

but if I debug(@film.live_action_personnel) earlier within the same
template, all is well!
It seems that ActiveRecord isn't generating the right query when I only
need to count the number of records.

Anyone know a way round this that doesn't involve writing my own sql?


Dorian M. (Guest)
on 2006-05-18 18:02
(Received via mailing list)

it appears that if I use
then all is ok.

My understanding is that this omits object caching of the sql, but I
can't see why it would change the actual sql produced.
Might this be a bug?

This topic is locked and can not be replied to.