Complex find

I have

class Debtortrans < ActiveRecord::Base
has_many :debtortranstaxes, :foreign_key =>
‘debtortransid’, :class_name => ‘debtortranstaxes’
belongs_to :debtor, :foreign_key => ‘debtorno’

and

class Debtortranstaxes < ActiveRecord::Base
belongs_to :debtortrans, :foreign_key => ‘debtortransid’

Now I want to find Debtortrans records but only those with specific
Debtortranstaxes values…

@debtor = Debtortrans.find(:all,
:conditions => [“trandate > ? and trandate < ? AND
debtortranstaxes.taxauthid = ?”, @per1, @per.lastdate_in_period, “24”],
:include => ‘debtortranstaxes’,
:select => ‘debtorno, trandate, transno, ovamount’)

but this gives me an error…
NameError: undefined local variable or method `debtortranstaxes’ for
#Class:0xb7a4e644

so I change the conditions to
:conditions => [“trandate > ? and trandate < ? AND taxauthid = ?”,
@per1, @per.lastdate_in_period, “24”],

and I get this error…
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ‘taxauthid’
in ‘where clause’: SELECT debtorno, trandate, transno, ovamount FROM
debtortrans WHERE (trandate > ‘2009-04-30’ and trandate < ‘2009-05-31’
AND taxauthid = ‘24’)

obviously because taxauthid column is not in debtortrans table but in
the ‘has_many’ table of debtortranstaxes.

How do I get the search of debtortrans with only appropriate records in
debtortranstaxes table?

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

On Tue, 2009-07-28 at 10:31 -0700, Craig W. wrote:

belongs_to :debtortrans, :foreign_key => ‘debtortransid’
but this gives me an error…
debtortrans WHERE (trandate > ‘2009-04-30’ and trandate < ‘2009-05-31’
AND taxauthid = ‘24’)

obviously because taxauthid column is not in debtortrans table but in
the ‘has_many’ table of debtortranstaxes.

How do I get the search of debtortrans with only appropriate records in
debtortranstaxes table?


I got this to work…had to use ‘joins’ instead of ‘include’ - duh

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.