• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Many-to-Many without Flattened Relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Many-to-Many without Flattened Relationship


  • Subject: Re: Many-to-Many without Flattened Relationship
  • From: Art Isbell <email@hidden>
  • Date: Sun, 26 Feb 2006 13:01:34 -1000

On Feb 26, 2006, at 12:12 PM, Anthony Martello wrote:

I have a three tables: Account, CourseAccess and Course. Each customer from Accounts can purchase access to one or more courses from Course for a limited time. Account has PK userId and Course has PK courseId. CourseAccess is a join table with attributes courseId, userId and endDate. To keep track of which user is purchasing the course, I have an instance of Account in the session named "account" and method currentAccount() which returns "account" (not sure if I need this last).

My questions are:

1) Is this the best way to set this up by keeping the endDate attribute in the join table?

The way I look at it, any attribute that isn't specific to all Accounts or all Courses but that is specific to each combination of Account and Course belongs in the join entity, CourseAccess. If the end date is for a particular Course, then it should by a Course attribute. But if it is the end date for access to a certain Course by a certain Account, then it should be a CourseAccess attribute. I could see both being possible in the real world, but you know your situation better than I do.


2) Once the relationship is set up in EOModeler: a) how do I add a course to a client (I assume I will use addObjectToBothSidesOfRelationshipWithKey) and b) how do I set the endDate in the join table?

You'd need to create a new CourseAccess object and set its end date:

CourseAccess courseAccess = (CourseAccess) EOUtilities.createAndInsertInstance(account.editingContext(), "CourseAccess");
courseAccess.setEndDate(endDate);


Then you would need to relate the Account, CourseAccess, and Course objects:

account.addObjectToBothSidesOfRelationshipWithKey(courseAccess, "courseAccesses");
course.addObjectToBothSidesOfRelationshipWithKey(courseAccess, "courseAccesses");


Sending the editing context a saveChanges() message should insert the new CourseAccess object and the various primary and foreign keys. It's usually good to watch the SQL that's generated by turning on adaptor debugging to ensure that the DB is being updated as expected.

Aloha,
Art

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


References: 
 >Many-to-Many without Flattened Relationship (From: Anthony Martello <email@hidden>)

  • Prev by Date: Many-to-Many without Flattened Relationship
  • Next by Date: Coca Enterprise Objects Application
  • Previous by thread: Many-to-Many without Flattened Relationship
  • Next by thread: Coca Enterprise Objects Application
  • Index(es):
    • Date
    • Thread