Re: How to fetch eo with a specific relationship
Re: How to fetch eo with a specific relationship
- Subject: Re: How to fetch eo with a specific relationship
- From: Louis Demers <email@hidden>
- Date: Wed, 6 Feb 2008 16:12:14 -0500
On 6-Feb-08, at 15:34 , Chuck Hill wrote:
On Feb 6, 2008, at 12:09 PM, Louis Demers wrote:
Thanks to all for quickly educating me on this subject.
On 6-Feb-08, at 11:32 , Robert Walker wrote:
1) that is a specific case where exposing/using primary keys is
OK ?
Well, you CAN use PK, even it is not a good idea to manipulate it
directly.
ERXGenericRecord, from Project Wonder, has the method
primaryKey() that return a string with the value of the PK, you
do not need to set the field as "manipulated" (I don't know how
to say it) in the EOModel.
EOFetchSpecification can use EOs. EOF will take care of performing
the fetch using the object's PK.
1. Find the Category object you're interested in.
2. Build a fetch specification using that category instance to
find the related products.
Example:
Category aCategory; // assume this exists
EOQualifier qual =
EOQualifier.qualifierWithQualifierFormat("category = %@", new
NSArray(aCategory));
EOFetchSpecification fs = new EOFetchSpecification("Product",
qual, null);
For no reason other than I like its expressiveness, if you use
Wonder you can just do this:
i do
EOFetchSpecification fs = new EOFetchSpecification("Product",
ERXQ.equals("category", aCategory), null);
cool, i like it too..
Thank Mike.
Thanks Mike
Chuck
Thanks Chuck
that is exactly what I was trying to figure out.
My intuition was steering me away from 2) but I could not remember
why or find the message where I had read about this performance
issue.
Thanks again Robert and the others.
2) setup the reverse to-many relationship ?
IMHO, this is the best way to do it:
always set a inverse toMany relation for every ToOne, well, if
you know that you'll never use it, you can avoid to set an
inverse relationship, but in this case, you should find it usefull.
At least if using standard EOF classes, having the reverse to-many
relationship as a class properly on the EO can cause very major
performance problems because the to-many fault can get fired when
you don't expect it. This can happen even if you never directly
access the to-many relationship. I've had nightmares about this
very problem in the past. I now consider the implication of adding
the to-many side as a class property. If I expect it could return
more than a few hundred objects then I don't use it. I still model
the to-many side, I just don't set it as a class property. It's
entirely possible that Project WOnder classes take care of this
problem. I just wanted to make sure you were aware of it.
You could also add method to the Category class using the above
fetch specification that returns the related parts in an array.
This way you can use it just like you had a relationship, but you
would not have to worry about the fault firing problem. This is
the approach I generally take when I'm concerned about the number
of related objects.
On Feb 6, 2008, at 10:26 AM, Daniele Corti wrote:
2008/2/6, Louis Demers <email@hidden>: Hi,
I have 2 EO, Part and Category. Part has a to-one relationship to
Category. Category does not have a reverse to-many relationship.
Through a search/listing page of categories, the user can select a
Category and I wish to present all of the parts from this
category. I
was hoping to not used the fields of the categories (like name,
type...) to do the search, and really use the EO itself as the
selection criteria. That lead meto consider using the primary
key, but
every book /messages I looked through discourages one to use
primary
keys/global ids. My guesses are:
1) that is a specific case where exposing/using primary keys is
OK ?
Well, you CAN use PK, even it is not a good idea to manipulate it
directly.
ERXGenericRecord, from Project Wonder, has the method
primaryKey() that return a string with the value of the PK, you
do not need to set the field as "manipulated" (I don't know how
to say it) in the EOModel.
2) setup the reverse to-many relationship ?
IMHO, this is the best way to do it:
always set a inverse toMany relation for every ToOne, well, if
you know that you'll never use it, you can avoid to set an
inverse relationship, but in this case, you should find it usefull.
3) set querybindings (I use Display groups a lot) using the key
name
of the relationship and the EO as the object and let WO figured it
out ? I seem to recall some message about this but could not
find it
or sample code for that.
Sorry, I've not understand what you do... can you give an example?
4) use the fields of the category to form a complete specification.
That seems unsuitable in case two categories are named the same
(temporarily due to a mixup).
You should consider to set an Unique field in your EO, like
categoryCode, it can also be Alphanumeric.
What is the real WOway of doing this.
I don't think there's an official WAY to do things, there are
tested ways, but I usually like to experience new chances by
myself.
Remember that WO allow you to do everything, so simply think of a
way and try. If it doesn't work, you can retry ;-P
Thanks in advance.
Louis Demers eng.
www.obzerv.com
_______________________________________________
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
--
Daniele Corti
AIM: S0CR4TE5
Messenger: email@hidden
--
Computers are like air conditioners -- they stop working properly
if you open
WINDOWS
--
What about the four lusers of the apocalypse? I nominate:
"advertising", "can't log in", "power switch" and "what backup?"
--Alistair Young
_______________________________________________
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
--
Robert Walker
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
Louis Demers eng.
www.obzerv.com
_______________________________________________
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
--
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
Louis Demers eng.
www.obzerv.com
_______________________________________________
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