Re: Using distinct in to-many relationship?
Re: Using distinct in to-many relationship?
- Subject: Re: Using distinct in to-many relationship?
- From: Marcos Trejo Munguia <email@hidden>
- Date: Mon, 21 Aug 2006 19:15:31 -0500
On Aug 21, 2006, at 6:41 PM, Chuck Hill wrote:
On Aug 21, 2006, at 4:21 PM, 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.
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.
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:
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
_______________________________________________
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