• 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
Adding Objects To Relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Adding Objects To Relationships


  • Subject: Adding Objects To Relationships
  • From: Owen McKerrow <email@hidden>
  • Date: Wed, 21 Feb 2007 10:26:02 +1100

Hi All,

The website Im currently working on has users entering entries for experinces. They need the ability to shift an element from one experience to another. So we have a pop-up under each element which shows all thr experiences the persons currently has, the select the experience they want the element to go to and hit the submit button. We can't bind the element.experience relationship to this pop-up as we need to do some other work before we shift it ( i.e. adjust the "order" element of all the other entries after this one, up one level ). Now this works fine the first time, the element is shifted to the new experience , its no longer displayed under the experience its left and when you navigate to the new experience its shown there. However if you send the element back to the experience it came from ( or any other experience for that matter ) it disappears altogether until you log back in with a new session. That is, it is no longer listed under the experience it was it, but it also doesn't show up under the experience it was assigned to.

So heres some code and then my thoughts on what may ( or may not ) be happening afterwards :
Note : ElementsExperince is the join between Element and Experince which holds the order attribute in it.


Experince.java's code for a experience to provide its active list of elements ( we don't delete elements we just set them to inactive so they are hidden ). This is called to display the elements for the experience that is currently selected.

Experince.java

public NSMutableArray activeElements()
{
if ( elementExperiences() != null ) {
NSMutableArray qualData = new NSMutableArray(new Integer(1));
EOQualifier qual = EOQualifier.qualifierWithQualifierFormat ("element.active = %@",qualData);
activeElements = (NSMutableArray) EOQualifier.filteredArrayWithQualifier(elementExperiences(),qual);
}
if ( activeElements.count() > 0 ) {
EOSortOrdering order1 = new EOSortOrdering ("elementOrder", EOSortOrdering.CompareAscending);
NSMutableArray orderings = new NSMutableArray(order1);
EOSortOrdering.sortArrayUsingKeyOrderArray (activeElements,orderings);
}
return activeElements;
}



And here the code from the component that shifts the element from one experience to the other.


public WOComponent shiftEntry()
{
//if the new Experince is different from the old one
if ( shiftEntrySelected() != elementsExperinceHolder().experience () ) {
//Shift all entries after this one up one position
// Update all the other element orders for all the other elements that come after it, before we shift it to the new entry
elementsExperinceHolder().experience().shiftOtherElementsOrderUp (elementsExperinceHolder());
//Move the entry to the end of the selected group
elementsExperinceHolder.setElementOrder(new Integer (shiftEntrySelected().activeElements().count()+1));
elementsExperinceHolder().setExperienceRelationship (shiftEntrySelected());
performParentAction("save");
performParentAction("updateList");
}
return context().page();
}



We're using EOGenerator and Jonathan's template files, so the code for setExperienceRelationship() looks like this :


public void setExperienceRelationship(Experience aValue) {
if( log.isDebugEnabled() ) log.debug( "updating experience from "+experience()+" to "+aValue );
if( aValue == null ) {
Experience object = experience();
if( object != null )
removeObjectFromBothSidesOfRelationshipWithKey ( object, "experience" );
} else
addObjectToBothSidesOfRelationshipWithKey( aValue, "experience" );
}



So following this through with the debugger what happens is that after we shift the entry for the 2nd time, its not being turned up in activeElements() for the group it belonged to ( correct behaviour) however it is also not appearing in the activeElements() for the group it was assigned to.


And finally heres some debug statements to show the count of all elements and active elements for the experiences as we travel through the scenario above...

Come to the page for the first time :
Experince : My Portfolio
Element Experinces count : 11
Active Element Experinces : 3

Shift the entry to the "My first prac experience" experience :

Experience : My first prac experience
Element Experinces count : 3
Active Element Experinces : 3

Experience : My Portfolio
Element Experiences count : 10 ( count has gone down by 1, correct)
Active Element Experiences : 2 ( count has gone down by 1, correct)

Navigate to the Experience :

Experience : My first prac experience
Element Experinces count : 4 ( count has gone up by 1, correct)
Active Element Experinces : 4( count has gone up by 1, correct)

Shift the entry back to "My Portfolio" :

Experince : My first prac experience
Element Experinces count : 3 ( count has gone down by 1, correct)
Active Element Experinces : 3 ( count has gone down by 1, correct)

Navigate back to first experience :

Experince : My Portfolio
Element Experinces count : 11 ( count has gone up by 1, correct)
Active Element Experinces : 2 ( count has stayed the same, incorrect)

So we can see from the last 2 lines that the element is being correctly re-assigned back to the first experience ( count goes back up to 11 ) but the activeElements() filter is getting it wrong, even though the filter is based upon the active status of the element itself, which is never touched. And as I said, it you log out and then come back in with a fresh session, its sitting there like its meant to be.

So the suspect code I believe is this bit from activeElements()

if ( elementExperiences() != null ) {
NSMutableArray qualData = new NSMutableArray(new Integer(1));
EOQualifier qual = EOQualifier.qualifierWithQualifierFormat ("element.active = %@",qualData);
activeElements = (NSMutableArray) EOQualifier.filteredArrayWithQualifier(elementExperiences(),qual);
}


Does anyone one have any suggestions or see anything I've done wrong ?

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

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

People who prefer typing to pointing then seem to prefer acronyms to save typing :-)
-Denis Stanton, On people using Command Line Interfaces



_______________________________________________ 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
  • Prev by Date: EOModeler, Project Builder won't launch on Windows XP
  • Next by Date: Re: EOModeler, Project Builder won't launch on Windows XP
  • Previous by thread: Re: EOModeler, Project Builder won't launch on Windows XP
  • Next by thread: EOModeler hangs
  • Index(es):
    • Date
    • Thread