cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

flexible search relacion many to many

Former Member
0 Likes
9,089

Hy everybody. I want to create a flexible search query to find all products for one vendor.

I have this code:

 "select {" + ProductModel.PK + "} FROM " +
             "{" + ProductModel._TYPECODE + " as p join productvendorrelation as pv on {p" + ProductModel.PK + "} = {pv.source} join " + VendorModel._TYPECODE + "as v on {pv.target} = {v"+ VendorModel.PK +"}}" +
             "where {v.pk} = ?vendorPk ";

The problem I have is that "productvendorrelation" is a many to many relation and I don't know how to access it if I don't have typecode.

The relation is:

 <relation code="ProductVendorRelation" autocreate="true"
             generate="false" localized="false">
             <deployment table="ProductVendorRel" typecode="2010" />
             <sourceElement type="Product" cardinality="many"
                 navigable="false" />
             <targetElement type="Vendor" qualifier="vendors"
                 collectiontype="set" cardinality="many" ordered="true">
                 <modifiers read="true" write="true" search="true"
                     optional="true" />
             </targetElement>
         </relation>


Thanx a lot.

Accepted Solutions (1)

Accepted Solutions (1)

arvind-kumar_avinash
Active Contributor

You can retrieve all the information from these tables based on the relation e.g. there is a many-to-many relation between Product and Category as shown below:

 <relation code="CategoryProductRelation" autocreate="true" generate="true" localized="false">
     <deployment table="Cat2ProdRel" typecode="143"/>
     <sourceElement qualifier="supercategories" type="Category" cardinality="many" ordered="false">
         <description>Super Categories</description>
         <modifiers read="true" write="true" search="true" optional="true"/>
     </sourceElement>
     <targetElement qualifier="products" type="Product" cardinality="many" collectiontype="list" ordered="true">
         <description>Products</description>
         <modifiers read="true" write="true" search="true" optional="true"/>
     </targetElement>        
 </relation>

and you can access whatever information you want using their relationship e.g.

 SELECT {p:PK}, {c:code} FROM
 {
    Product as p JOIN CategoryProductRelation as rel
    ON {p:PK} = {rel:target}
    JOIN Category AS c
    ON {rel:source} = {c:PK}
 }

What else do you want to achieve?

I think you are confused with ProductModel_TYPECODE. Please note that ProductModel_TYPECODE= "Product" i.e. instead of writing ProductModel_TYPECODE you can simply write Product.

Please let me know if you have further doubt.

Answers (1)

Answers (1)

Former Member
0 Likes

thanx. I was trying to use use the join with the ._TYPECODE of the relationes table but I can use just the name of the table as in the example and it works perfectly ;)

arvind-kumar_avinash
Active Contributor
0 Likes

You are most welcome.