Hi, Jim,

On Feb 26, 2006, at 3: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?

A flattened relationship is a relationship whose definition in the EOModel is based on the definition of another relationship in such a way that you don't have to use the base relationship in your code.

So, for your problem you have three entities in the following structure:

    COMPANY <->> OPPORTUNITY_COMPANY <<-> OPPORTUNITY

This structure, however, is an artifact of relational databases and is the solution that they force on you when what you really want is this structure:

   COMPANY <<->> OPPORTUNITY

Even though this latter structure is perfectly acceptable in your object graph where a Company instance would have an NSArray attribute named opportunities whose elements each point to a related opportunity and where an Opportunity instance would have an NSArray attribute named companies whose elements each point to a related company, it simply can't be reflected in the relational database and still have the database be relational. Notice that in the object graph, then, there is no direct correspondence to the OPPORTUNITY_COMPANY table.

So, EOModel lets you create a pseudo-relationship in each of COMPANY and OPPORTUNITY to represent the NSArrays that will be derived, and each of these pseudo-relationships is defined on the underlying real relationship (real in the sense that it's directly reflected in the relational model). Finally, the diamond in EOModeler that determines whether an EOEntity's attribute or relationship is reflected in the object graph as a class property is removed so that the "real" relationships are not reflected anywhere in the object graph, but are replaced by the "pseudo-relationships".

This replacement in the EOModel and, as a consequence, in the class model of the "real" relationships by the "pseudo-relationships" is called flattening the relationships.

From the EOModeler User Guide:

A flattened attribute is a special kind of attribute that you effectively add from one entity to another
by traversing a relationship. When you form a to-one relationship between two entities (such as
Person and PersonPhoto), you can add attributes from the destination table to the source table.

Regarding their downsides and when they should be used, take a look at the EOModeler User Guide under flattened relationships and flattened attributes. You can find the guide at:


Regards,
Jerry


Warmest Regards,
Jim Wong



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.

Aloha,
Art

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:

This email sent to [EMAIL PROTECTED]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:

This email sent to [EMAIL PROTECTED]


--
__ Jerry W. Walker,
   WebObjects Developer/Instructor for High Performance Industrial Strength Internet Enabled Systems

    jerrywwalker@gee-em-aye-eye-ell.com
    203 278-4085        office



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to