Hello Jim,
You'll be safest if you stick to using flattened relationships for many-to-many's, and for nothing else.
I haven't used Art's method, but he says it'll create the flattened relationship for you, so just leave it at that. Make sure the non-flattened relationships (the ones directly to and from OPPORTUNITY_CUSTOMER) are not exposed to the class (uncheck the diamond column in EOModeler, and make sure any java classes don't have methods calling those relationships directly).
Finally, you can modify the code I sent earlier like this (and again, I haven't run or debugged this):
public boolean opportunityHasCompany() {
return anOpportunity.companies().containsObject( currentCompany );
}
public void setOpportunityHasCompany( boolean value ) {
if( value && !opportunityHasCompany() ) {
anOpportunity.addObjectToBothSidesOfRelationshipWithKey( currentCompany, "companies" );
}
if( !value && opportunityHasCompany() ) {
companyArray.removeObjectFromBothSidesOfRelationshipWithKey( currentCompany, "companies" );
}
}
Where "companies" is the flattened many-to-many from Opportunity to Company, anOpportunity is the Opportunity being modified, and currentCompany is the "item" in the WORepetition.
Regards,
Mark
On Feb 26, 2006, at 2:21 AM, Jim Wong wrote:
thanks art.
what's flattened relationships? i can't catch wat the WO tutorial is talking abt. when do i use flattened and when do i not use? any pros and cons?
On 26 Feb 2006, at 4:10 PM, Art Isbell wrote:
On Feb 25, 2006, at 9:10 PM, Jim Wong wrote:
I have 3 entities: COMPANY, OPPORTUNITY, OPPORTUNITY_COMPANY.
COMPANY
- companyID (attribute)
OPPORTUNITY
- oppID (attribute)
- customer (relationship between OPPORTUNITY(oppID) and OPPORTUNITY_COMPANY (oppID))
OPPORTUNITY_CUSTOMER
- oppID (attribute)
- customerID (attribute)
- company (relationship between OPPORTUNITY_CUSTOMER (customerID) and COMPANY (companyID))
- opportunity (relationship between OPPORTUNITY_CUSTOMER (oppID) and OPPORTUNITY (oppID))
The requirements of a form are:
- In a form which displays all companies in COMPANY, user can select by WOCheckBOX the company(s) which will be customer of an opportunity.
- Upon submission, the selected companies needs to be added to the OPPORTUNITY_CUSTOMER as customers of a related OPPORTUNITY.
how can i get the above done? how's the coding requirement be like?
EOModeler can build a valid many-to-many relationship between Company and Opportunity. This is preferable to building these relationships manually because it's easy to make a mistake. Click the Tools > Table Mode EOModeler menu. Select the model name (the top node along the left edge of the EOModeler window). In the right section of the window, select the Company and Opportunity entities. Click the Property > Join in Many to Many menu item. This will create Company.opportunities and Opportunity.companies to-many relationships that are flattened across the Opportunity_Company join entity. Inspect the Opportunity_Company entity to make sure that it has the correct table name. You may rename the Opportunity_Company entity to Opportunity_Customer and the Opportunity.companies relationship to Opportunity.customers if you prefer.
Then when the form is submitted, iterate through the selected companies adding each company to the Opportunity.customers relationship:
opportunity.addObjectToBothSidesOfRelationshipWithKey(selectedCompany, "customers");
Then send a saveChanges() message to the editing context. Your eomodel will guide EOF to automatically manage the Opportunity_Customer entity which you don't need to refer to in your code or even to generate a custom Java class for; just leave it an EOGenericRecord.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Help/Unsubscribe/Update your Subscription:
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Help/Unsubscribe/Update your Subscription:
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Help/Unsubscribe/Update your Subscription: