hmm....
it appears that if I use
@film.live_action_personnel(true).size
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?
dorian
Dorian Mcfarland wrote:> Hi, 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 =>
>
''credit_types.personnel_type="live_action_personnel"''
>
>
> 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
> (credit_types.personnel_type="live_action_personnel"))
>
> 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?
>
> thanks
>
> dorian
>
--
--
I do things for love or money