Link to home
Start Free TrialLog in
Avatar of adam1h
adam1hFlag for Belgium

asked on

Coldfusion orm oneToMany join query don't work

I have 2 persistent entities : Product & ProductMaterial.

Product can't be sumarize like This :

<cfproperty name="id" type="numeric" fieldtype="id" ormtype="int" generator="native" setter="false" hint="the unique id of the product">
...
<cfproperty name="materials" type="array" fieldtype="one-to-many" hint="the materials of the product" cfc="ProductMaterial" singularname="material" fkcolumn="productId"    orderby="name"  cascade="all-delete-orphan">

Open in new window


And ProductMaterial is :

<cfproperty name="id" type="numeric" fieldtype="id" ormtype="int" generator="native" setter="false" hint="the unique id of the material">
<cfproperty name="name" type="string" fieldtype="column" ormtype="string" length="50" validate="string" validateparams="{minLength=1,maxLength=50}" hint="the name of the material">

Open in new window


I want to get the products according a selected material, for instance 'Wood'

I have tried, among other things similar, this :

<cfset variables.products = ormExecuteQuery("from Product p join p.materials m where m.name = 'wood' and isPack=true order by referenceId desc")>

Open in new window


But it returns me 0 records (there must be 433 records !).

Do u have an idea what's wrong ?

Thanks.
Avatar of James Rodgers
James Rodgers
Flag of Canada image

the join doesn't seem correct


from Product p join p.materials m where m.name

should either be
 from Product p, materials m
Where p.col=m.com and m.name =

or
from Product p
LEFT JOIN  Materials m
on p.col=m.col
WHERE m.name=
ASKER CERTIFIED SOLUTION
Avatar of adam1h
adam1h
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adam1h

ASKER

I have receive no corect answer, I have found myself the solution (as described in the comment).