Hi there, I am in the process of writing a couple of fairly complex OQL queries for our reporting purposes. I've written the initial query and it is working, but now I want to make the java action a bit more dynamic. What I want to know is, if I've got two entities, how can I get the association name between them? In the query : SELECT * FROM Sales.Customer INNER JOIN Sales.Customer/Sales.Customer_Address/Sales.Address how can I get Sales.Customer_Address, if I only have Sales.Customer & Sales.Address What I want in the end is : String entityName1 = Customer.entityName; String entityName2 = Address.entityName; String assocName = someMethodToGetAssociationName(entityName1, entityName2); String strOQL = "SELECT * FROM " + entityName1 + " INNER JOIN " + entityName1 + "/" + assocName + "/" + entityName2; Any Ideas?
You can use Core.getMetaObject(entityName1) to get an IMetaObject instance. IMetaObject has methods like getMetaAssociationsParent() and getMetaAssociationsChild() to retrieve a collection of associations from which the entity1 is the parent or the child. When you have found an IMetaAssociation with entity2 as child or parent, you have the association between them entity1 and entity2.