I have an ActiveRecord class that has several has_many,belongs_to,
habtm, and the new has_many => :through relationships.
Whenever I try a
find(:all, :conditions => “some conds”, :include [:relationship])
it works fine, but if I have
find(:all, :conditions => “some conds”, :include [:relationship,
:other_relation])
it gets a sql error such as
Mysql::Error: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near …
I’ll paste the actual output below, but what I’ve found is that there is
a stray pipe character ( | ) near the LEFT OUTER JOIN statements. I
have no idea why its there, but if I remove it and paste the result into
the mysql command line, the query succeeds. Does anyone know what is
going on here? Is this a bug? Thanks for the help. Here’s the whole
error. I know its really long, but just search for the | and you’ll see
what I mean. Thanks again.
John
ActiveRecord::StatementInvalid (Mysql::Error: You have an error in your
SQL synt ax; check the manual that corresponds to your MySQL
server version for the right syntax to use near ‘OUTER JOIN
mechanisms ON mechanisms.id = grants.mechanism_i d WHERE ( (
title LI’ at line 1: SELECT grants.id
AS t0_r0, grants.brown_gra nt_identifier
AS t0_r1, grants.account
AS t0_r2,
grants.grant_type_id
AS t0 _r3, grants.mechanism_id
AS
t0_r4, grants.sponsor_agency_id
AS t0_r5, grants
.award_year_indicator_id
AS t0_r6, grants.grant_home_id
AS t0_r7,
grants.sp onsor
AS t0_r8, grants.fund_source
AS t0_r9,
grants.department_name
AS t0_r 10,
grants.start_date_overall
AS t0_r11, grants.end_date_overall
AS
t0_r12, grants.start_date_current
AS t0_r13,
grants.end_date_current
AS t0_r14, gran ts.total_amount
AS
t0_r15, grants.direct_amount
AS t0_r16, grants.indirect_ amount
AS t0_r17, grants.total_amount_cfy
AS t0_r18,
grants.direct_amount_cf y
AS t0_r19,
grants.indirect_amount_cfy
AS t0_r20, grants.title
AS t0_r21,
grants.abstract
AS t0_r22, grants.created_at
AS t0_r23,
grants.created_on
AS t0_r24, grants.updated_at
AS t0_r25,
grants.updated_on
AS t0_r26, grants. lock_version
AS
t0_r27, grants.created_by
AS t0_r28, grants.updated_by
AS
t0_r29, sponsor_agencies.id
AS t1_r0, sponsor_agencies.name
AS
t1_r1, sponso r_agencies.address
AS t1_r2,
sponsor_agencies.phone
AS t1_r3, sponsor_agenci
es.contact_name
AS t1_r4, sponsor_agencies.created_at
AS t1_r5,
sponsor_agen cies.created_on
AS t1_r6,
sponsor_agencies.updated_at
AS t1_r7, sponsor_agen
cies.updated_on
AS t1_r8, sponsor_agencies.lock_version
AS t1_r9,
sponsor_ag encies.created_by
AS t1_r10,
sponsor_agencies.updated_by
AS t1_r11, mechanis ms.id
AS
t2_r0, mechanisms.name
AS t2_r1, mechanisms.description
AS t2_r2,
mechanisms.created_at
AS t2_r3, mechanisms.created_on
AS t2_r4,
mechanisms. updated_at
AS t2_r5, mechanisms.updated_on
AS
t2_r6, mechanisms.lock_versio n
AS t2_r7,
mechanisms.created_by
AS t2_r8, mechanisms.updated_by
AS t2_r9
FROM grants LEFT OUTER JOIN sponsor_agencies ON sponsor_agencies.id =
grants.sp onsor_agency_id | LEFT OUTER JOIN mechanisms ON
mechanisms.id = grants.mechanism _id WHERE ( ( title LIKE
‘%rasoulpour%’ OR abstract LIKE ‘%rasoulpour%’ OR
department_name LIKE ‘%rasoulpour%’ OR fund_source LIKE ‘%rasoulpour%’
) ) )