• 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: Problems with addObjectToBothSidesOfRelationshipWithKey
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with addObjectToBothSidesOfRelationshipWithKey


  • Subject: Re: Problems with addObjectToBothSidesOfRelationshipWithKey
  • From: Owen McKerrow <email@hidden>
  • Date: Fri, 19 Oct 2007 11:38:54 +1000

Upon double checking personID was, yes. I change it so it wasn't but that didn't help the problem.

Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"As of tomorrow, employees will only be able to access the building using individual security cards. Pictures will be taken next Wednesday employees will receive their cards in two weeks."
- "Dilbert Quotes" Winner, Fred Dales, Microsoft Corp



On 19/10/2007, at 11:32 AM, Simon McLean wrote:

is either rowID or personID set as a class property in EOModeler ?

Simon


On 19 Oct 2007, at 02:24, Owen McKerrow wrote:

Hi All,

Im having a problem with addObjectToBothSidesOfRelationshipWithKey, either that or I don't understand how its meant to work correctly. That is when you use addObjectToBothSidesOfRelationshipWithKey the relationships between both objects should be updated. So if you have a relationship between a dog and a cat, when you use addObjectToBothSidesOfRelationshipWithKey to set the dog's relationship to cat, its should auto set the cat's relationship back to the dog.

Im writing some code for my Person class, which when given another person "merges" them into itself. That is sets all of the given persons relationships to the first person.
Now Person has a toMany relationship with AuthorPubs and AuthorPubs has a toOne relationship back to Person. Set up like this inside EOModler :


Table : Person
Relationship : publicationsAuthorOf, toMany, optional
Destination : AuthorPubs
Source Att : rowID
Dest Att : personID

Table : AuthorPubs
Relationship : person, toOne, mandetory
Destination : Person
Source Att : personID
Dest Att : rowID


Now here's the code inside the Person class that does the "merging" :


public void mergePersonIntoMe(Person person, boolean delete) throws Exception
{
.....
swaptoMe(person.publicationsAuthorOf(),inverseForRelationshipKey ("publicationsAuthorOf"));
....
}


/**
Given an array of objects and a relationship name, change all the objects so that they belong to this person
*/
public void swaptoMe(NSArray theItems, String relationshipName) throws Exception
{
int i;
log.debug("Reverse relationship is : " + relationshipName);
if (theItems != null ) {
for (i=0;i<theItems.count();i++) {
try {
OMGenericRecord tempRec = (OMGenericRecord) theItems.objectAtIndex(i);
tempRec.addObjectToBothSidesOfRelationshipWithKey (this,relationshipName);
//Check if we are copying across author/editors, if so we nee to update their name
if (tempRec instanceof AuthorPubs ) {
log.debug("Person for publication : " + tempRec.valueForKey (relationshipName));
if (publicationsAuthorOf().containsObject(tempRec) ) {
log.debug("Person is author.");
} else if (publicationsEditorOf().containsObject(tempRec)){
log.debug("Person is editor.");
} else {
log.debug("Person is not associated with the publication");
}
tempRec.takeValueForKey(firstNameToUseForPublications (),"firstName");
tempRec.takeValueForKey(lastNameToUseForPublications (),"lastName");
tempRec.takeValueForKey(middleNameToUseForPublications (),"middleName");
}
} catch ( Exception ex) {
throw ex;
}
}
}
}


OK so I go to merge the person S Anderson into Sharon Anderson.

Now heres the output from those debug statements :

11:18:40,038 DEBUG [WorkerThread3] (Person:2284 swaptoMe) - Reverse relationship is : person
11:18:40,039 DEBUG [WorkerThread3] (Person:2290 swaptoMe) - Person for publication before swap : External:(Active_Name=S Anderson) {rowID=11477;}
11:18:40,046 DEBUG [WorkerThread3] (Person:2295 swaptoMe) - Person for publication after swap : Researcher:(Active_Name=Sharon Anderson, Staff_Number=xxx){rowID=10000;}
11:18:40,047 DEBUG [WorkerThread3] (Person:2301 swaptoMe) - Person is not associated with the publication
11:18:40,049 DEBUG [WorkerThread3] (Person:2290 swaptoMe) - Person for publication before swap : External:(Active_Name=S Anderson) {rowID=11477;}
11:18:40,050 DEBUG [WorkerThread3] (Person:2295 swaptoMe) - Person for publication after swap : Researcher:(Active_Name=Sharon Anderson, Staff_Number=xxx){rowID=10000;}
11:18:40,050 DEBUG [WorkerThread3] (Person:2301 swaptoMe) - Person is not associated with the publication
11:18:40,051 DEBUG [WorkerThread3] (Person:2290 swaptoMe) - Person for publication before swap : External:(Active_Name=S Anderson) {rowID=11477;}
11:18:40,053 DEBUG [WorkerThread3] (Person:2295 swaptoMe) - Person for publication after swap : Researcher:(Active_Name=Sharon Anderson, Staff_Number=xxx){rowID=10000;}
11:18:40,054 DEBUG [WorkerThread3] (Person:2301 swaptoMe) - Person is not associated with the publication


As you can see the AuthorPubs person is changed to the new person. However this person has not had the AuthorPub added back to them.

The changes are made in the database and if I log out and log back in its all nice and happy.

Can someone see something dumb Im doing ? Am I not understanding the behavior of addObjectToBothSidesOfRelationshipWithKey correctly ?

Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

"I like the way this project has somehow, against all common sense, got itself made."
- Peter Jackson, "The Lord of The Rings"



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


This email sent to email@hidden


_______________________________________________ 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: 
 >Problems with addObjectToBothSidesOfRelationshipWithKey (From: Owen McKerrow <email@hidden>)

  • Prev by Date: Re: Problems with addObjectToBothSidesOfRelationshipWithKey
  • Next by Date: Re: Problems with addObjectToBothSidesOfRelationshipWithKey
  • Previous by thread: Re: Problems with addObjectToBothSidesOfRelationshipWithKey
  • Next by thread: MainBundle.woa?
  • Index(es):
    • Date
    • Thread