• 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: Using distinct in to-many relationship?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using distinct in to-many relationship?


  • Subject: Re: Using distinct in to-many relationship?
  • From: Chuck Hill <email@hidden>
  • Date: Tue, 22 Aug 2006 13:14:04 -0700


On Aug 22, 2006, at 7:04 AM, Marcos Trejo Munguia wrote:

Actually I,m using the EOFetchSpecification constructor that pass that parameter:

public EOFetchSpecification(String entityName,
                            EOQualifier qualifier,
                            NSArray sortOrderings,
                            boolean usesDistinct,
                            boolean isDeep,
                            NSDictionary hints)

I,m passing true in usesDistinct, I suppose that it have the same effect as setUsesDistinct(true). The problem is not with the main entity but with the relationships passed in setPrefetchingRelationshipKeyPaths, more specifically with to- many relationships.\

I am wondering if you are mis-understanding something. The distinct setting only applies to the objects that the fetch spec returns. The objects returned don't include the pre-fetched objects. Those are just fetched and cached, accessible by navigating relationships. The objects that the fetch returns are only those of entityName specified by qualifier.

I've discovered that today, also I've discovered that pre-fetched objects in to-one relationships are fetched using DISTINCT and to- many relationships don't. I know this because I'm debugging the generated SQL. My model looks like this:


A <<-> B <->> C

I do the fetch of A, and pre-fetch of B and C, I'm getting duplicates of C.

You may be fetching duplicates of C but EOF should not be creating duplicate objects. The fetching of duplicate rows is possibly a performance issue but should not affect the EO space.


Actually duplicate EOs are being created,

I doubt that they are. :-) Lists may have the same object in them more than once, but that does not mean that EOF created duplicate objects. If you find two objects that look to be the same, but which have different EOGlobalID values, then EOF has created a duplicate. Otherwise, what you have is the same object in a relationship multiple times and that is a very different problem.



I noticed that because I'm using the to-many relationship in a WORepetition.

It still sounds to me like you have a modeling or code error in those relationships. I have never seen EOF include an object multiple times unless I have somehow confused it.



Just one more question, if I do the fetch of objects of C in another fetch specification using DISTINCT, the fetched objects are available through A->B->C or another fetch is performed?

If you just navigate relationships, EOF will used the cached data -- unless the cached data has expired by the time you navigate the relaltionship.


Again, look at batch faulting.



Chuck




How are you determining that you are getting duplicate objects in the prefetched to-many relationships? I suspect that your bug lies elsewhere.

I ran the generated SQL directly in my db console, there is where I saw that I was getting duplicates.

It may be worth considering batch faulting as an alternative to prefetching.


Chuck



On Aug 21, 2006, at 1:41 PM, Zak Burke wrote:

Marcos Trejo Munguia wrote on 8/21/06 2:17 PM:
Recently I found that the SQL generated by a fetch using
setPrefetchingRelationshipKeyPaths with a to-many relationship generates
the query without distinct while for to-one relationships uses distinct.

Call setUsesDistinct(true) on your fetch-spec.

I just discovered this too. It was the source of some very mysterious
seeming behaviour -- extra copies of EOs would show up in lists with
(seemingly) no explanation.


From the javadoc:

public void setUsesDistinct(boolean usesDistinct) Sets whether duplicate objects or records are removed after fetching. If flag is true they are removed (that is, proper sets are returned). If flag is false they aren't (multisets are returned). EOFetchSpecifications by default don't use distinct.

zak.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
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






--

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


  • Follow-Ups:
    • Re: Using distinct in to-many relationship?
      • From: Marcos Trejo Munguia <email@hidden>
References: 
 >Using distinct in to-many relationship? (From: Marcos Trejo Munguia <email@hidden>)
 >Re: Using distinct in to-many relationship? (From: Zak Burke <email@hidden>)
 >Re: Using distinct in to-many relationship? (From: Marcos Trejo Munguia <email@hidden>)
 >Re: Using distinct in to-many relationship? (From: Chuck Hill <email@hidden>)
 >Re: Using distinct in to-many relationship? (From: Marcos Trejo Munguia <email@hidden>)
 >Re: Using distinct in to-many relationship? (From: Chuck Hill <email@hidden>)
 >Re: Using distinct in to-many relationship? (From: Marcos Trejo Munguia <email@hidden>)

  • Prev by Date: Re: EOGenerator and takeStoredValueForKey dumb question
  • Next by Date: Re: WebObjects Foundation
  • Previous by thread: Re: Using distinct in to-many relationship?
  • Next by thread: Re: Using distinct in to-many relationship?
  • Index(es):
    • Date
    • Thread