Re: My first web app... (still)
Re: My first web app... (still)
- Subject: Re: My first web app... (still)
- From: Chuck Hill <email@hidden>
- Date: Tue, 5 Jun 2007 21:43:37 -0700
Chuckle. Happy to hear that you are back on track!
Chuck
On Jun 5, 2007, at 9:39 PM, Mac Campbell wrote:
Wow... I can't believe I did not see this! This drove me crazy for
a good embarrising while! And I banged my head against it thinking
it was some strange intricacy of WebObjects and many to many
relationships... and really all along it was just a gaping hole in
my logic! :o|
Thanks Chuck that was extrermly helpful.
Mac
> CC: email@hidden
> From: email@hidden
> Subject: Re: My first web app... (still)
> Date: Tue, 5 Jun 2007 20:06:59 -0700
> To: email@hidden
>
>
> On Jun 5, 2007, at 7:46 PM, Mac Campbell wrote:
>
> >
> > No I haven't added any custom code to BlogEntrys for mainpulating
> > tags... I just have the standard methods that where created using
> > EOModeler...
> >
> > Attached is a screen shoot of my relationships (is this how people
> > usually share this info?)
>
> It works! :-)
>
>
> > Thanks for helping a very new green guy.
> >
> > Mac
> >
> > P.S. I commented out the else statement and just dealt with all
> > comments with the suggested method... and it did create new tag
> > entrees even if the tag was already in the tag table...
>
> "commented out the else" that does not sound right. The correct
> code should look like
>
> // if we find a positive result for our search
> if(result.count() > 0) {
> // grab that existing tag and add it to BlogEntrys tagss
> relationship for newEntry
> existingTag = (Tags)result.objectAtIndex(0);
> newEntry.addObjectToBothSidesOfRelationshipWithKey
> (existingTag, "tagss");
>
> } else {
>
> //if there is no positive result, add new Tag normally
> EOEnterpriseObject newTag =
> EOUtilities.createAndInsertInstance(ec, "Tags");
> newTag.takeValueForKey(tempString, "desc");
> newEntry.addObjectToBothSidesOfRelationshipWithKey
> (newTag, "tagss");
> }
>
>
> Or, if you want to condense it a bit:
>
> Tags selectedTag;
> // if we find a positive result for our search
> if(result.count() > 0) {
> // grab that existing tag and add it to BlogEntrys tagss
> relationship for newEntry
> selectedTag = (Tags)result.objectAtIndex(0);
>
> } else {
>
> //if there is no positive result, add new Tag normally
> EOEnterpriseObject selectedTag =
> EOUtilities.createAndInsertInstance(ec, "Tags");
> selectedTag.takeValueForKey(tempString, "desc");
> }
> newEntry.addObjectToBothSidesOfRelationshipWithKey
> (selectedTag, "tagss");
>
>
> Chuck
>
>
>
> > > CC: email@hidden
> > > From: email@hidden
> > > Subject: Re: My first web app... (still)
> > > Date: Tue, 5 Jun 2007 19:10:47 -0700
> > > To: email@hidden
> > >
> > >
> > > On Jun 5, 2007, at 6:29 PM, Mac Campbell wrote:
> > >
> > > > Chuck your brilliant,
> > > >
> > > > I apologize for not picking up on this sooner, I have
stepped away
> > > > from this project for at least a few months, so now I am
coming
> > > > back to it and ... learning as I go again...
> > > >
> > > > Chuck is absolutely right it has to do with my method of
inserting
> > > > the tags... below is an excerpt for how I deal with the
tag, if
> > > > it's a net new tag or if it's an existing tag...
> > >
> > > We might have a terminology difference here and some context
> > > information would help. I am guessing that you are letting
the user
> > > enter some text (tempString) for a Tag to tag a post with.
Either it
> > > matches an existing tag, or you create a new one. Am I close?
> > >
> > >
> > > > if it is a brand new tag it uses the
> > > > addObjectToBothSidesOfRelationshipWithKey and as Chuck
predicts
> > > > that works fine, however if it's an existing tag no such
luck...
> > > > until the app is stopped and started... I came up with this
hair
> > > > brain scheme to avoid having multiple entrees of the same
tag in
> > > > the tag table...
> > > > using addObjectToBothSidesOfRelationshipWithKey adds the tag
> > > > whether or not it's already in the table..
> > >
> > > It certainly should not!
addObjectToBothSidesOfRelationshipWithKey
> > > should work and should be used in either case. I suspect
something
> > > else is wrong. Perhaps your model is not correct. Have you added
> > > any code to BlogEntry that is manipulating tags?
> > >
> > >
> > > > any better ideas about how to over come this? Thanks again.
> > (It's a
> > > > many to many relationship that I let webobjects magic build
the
> > > > intermediary table for... tagmaps)
> > > >
> > > > // if we find a positive result for our search
> > > > if(result.count() > 0) {
> > > > // grab that existing tag and add it to BlogEntrys
> > > > tagss relationship for newEntry
> > >
> > > Yesss, my precioussssss. :-P Entity names should not get
> > > pluralized. That avoids names like BlogEntrys tagss and gives
names
> > > like BlogEntry tags. Unless you are aiming for a nickname of
> > Golem...
> > >
> > >
> > > > Tags existingTag = new Tags();
> > > That line is not needed
> > >
> > >
> > > > existingTag = (Tags)result.objectAtIndex(0);
> > > > newEntry.addObjectToPropertyWithKey(existingTag, "tagss");
> > >
> > > That _should_ work with
addObjectToBothSidesOfRelationshipWithKey
> > >
> > >
> > >
> > > > } else {
> > > >
> > > > //if there is no positive result, add new Tag normally
> > > > EOEnterpriseObject newTag =
> > > > EOUtilities.createAndInsertInstance(ec, "Tags");
> > > > newTag.takeValueForKey(tempString, "desc");
> > >
> > > Eewwww! That is misusing / abusing KVC. You _can_ do that,
but it
> > > makes your code brutal ugly and hard to read.
> > >
> > > newTag.setDesc(tempString);
> > >
> > >
> > > > newEntry.addObjectToBothSidesOfRelationshipWithKey
> > > > (newTag, "tagss");
> > > > }
> > >
> > >
> > > Still not sure what is wrong, but it lies elsewhere.
> > >
> > >
> > > Chuck
> > >
> > > >
> > > >
> > > >
> > > > > CC: email@hidden
> > > > > From: email@hidden
> > > > > Subject: Re: My first web app... (still)
> > > > > Date: Tue, 5 Jun 2007 10:00:46 -0700
> > > > > To: email@hidden
> > > > >
> > > > >
> > > > > On Jun 4, 2007, at 10:14 PM, Mac Campbell wrote:
> > > > >
> > > > > > Hello all,
> > > > > >
> > > > > > Maybe you can help me out with another question...
> > > > > >
> > > > > > I am working on a blog app as my first app... I have 3
major
> > > > > > outstanding issues the major one that I am most lost on
> > is... my
> > > > > > tag system does not increment the tag counts right
away... the
> > > > only
> > > > > > way the tag area shows the correct number of tags (for
> > newly added
> > > > > > tags, in debug mode) is for me to stop and start the app
> > (in Xcode
> > > > > > newest / last version) and start it again, although
added blog
> > > > > > posts do appear in the blog posts list...
> > > > >
> > > > > The primary cause of this is not correctly updating the
> > object graph
> > > > > when adding new objects. How are you adding the tag? You
> > should be
> > > > > using the addObjectToBothSidesOfRelationshipWithKey method.
> > Or, as
> > > > > Mike will soon say, use Wonder and his EOGenerator templates
> > from
> > > > the
> > > > > WO wiki so that you don't have to remember to do this. For
> > you, for
> > > > > now, I would just use that method.
> > > > >
> > > > >
> > > > > > I have the WO Repetition that goes through my array of
> > tagEntries
> > > > > > displaying each unique tagEnumerator pertinent code below
> > on the
> > > > > > main page:
> > > > > >
> > > > > > public NSArray tagEntries()
> > > > > > {
> > > > > >
> > > > > > tagEnumerator = null;
> > > > > > tEntrys = null;
> > > > > > //EOEditingContext ec3 = new EOEditingContext();
> > > > > > BlogEntry blogEntrys = new BlogEntry();
> > > > > > EOFetchSpecification fs =
> > > > > > EOFetchSpecification.fetchSpecificationNamed
("tagsDescending",
> > > > > > "Tags");
> > > > >
> > > > >
> > > > > > NSArray keypaths = new NSArray();
> > > > > > keypaths = keypaths.arrayByAddingObject("blogEntrys");
> > > > > >
> > > > > > //keypaths = "blogEntrys";
> > > > > > fs.setPrefetchingRelationshipKeyPaths(keypaths);
> > > > >
> > > > > Not related, but you are writing too much code;
> > > > >
> > > > > fs.setPrefetchingRelationshipKeyPaths(new NSArray
> > ("blogEntrys"));
> > > > >
> > > > > You might also want
> > > > >
> > > > > fs.setRefreshesRefetchedObjects(true);
> > > > >
> > > > >
> > > > > > NSArray tEntrys= new NSMutableArray(ec
> > > > > > ().objectsWithFetchSpecification(fs));
> > > > > > return tEntrys;
> > > > > > }
> > > > > >
> > > > > > After a new blog post is added (on the addPost page) the
> > main page
> > > > > > is called:
> > > > > >
> > > > > > ....
> > > > > > // commit the changes made to the objects in the editing
> > > > > > context to the database
> > > > > > ec.saveChanges();
> > > > > >
> > > > > > // refresh the page by fetching the page without
recreating
> > > > > > a new session
> > > > > > //Main nextPage = (Main)pageWithName("Main");
> > > > > > return pageWithName("Main");
> > > > > > }
> > > > > >
> > > > > > The thing in WO Repitetion doing the actual count is
> > > > > > "tagEnumerator.blogEntrys.@count"
> > > > > >
> > > > > > Any ideas? It only shows an accurate count when you first
> > start up
> > > > > > the app...?
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Mac
> > > > > > _______________________________________________
> > > > > > Do not post admin requests to the list. They will be
ignored.
> > > > > > Webobjects-dev mailing list (Webobjects-
email@hidden)
> > > > > > Help/Unsubscribe/Update your Subscription:
chill%
> > > > > > 40global-village.net
> > > > > >
> > > > > > This email sent to email@hidden
> > > > >
> > > > > --
> > > > >
> > > > > Practical WebObjects - for developers who want to
increase their
> > > > > overall knowledge of WebObjects or who are trying to solve
> > specific
> > > > > problems.
> > > > > http://www.global-village.net/products/practical_webobjects
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > >
> > > --
> > >
> > > Practical WebObjects - for developers who want to increase their
> > > overall knowledge of WebObjects or who are trying to solve
specific
> > > problems.
> > > http://www.global-village.net/products/practical_webobjects
> > >
> > >
> > >
> > >
> > >
> > <Picture 1.png>
>
> --
>
> Practical WebObjects - for developers who want to increase their
> overall knowledge of WebObjects or who are trying to solve specific
> problems.
> http://www.global-village.net/products/practical_webobjects
>
>
>
>
>
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
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