Re: (no subject)
Re: (no subject)
- Subject: Re: (no subject)
- From: wojingo <email@hidden>
- Date: Tue, 07 Feb 2006 10:32:18 +1030
Hi Scott,
Scott Winn wrote:
Hello WO Gurus,
I need a good example of how to search my EOModeled database using
relationships. Both of the books I have purchased have remarkably
little to say on the subject. Here are the entities and their relevant
attributes. . .
Company
(PK) company_id
Relationship: Sellers (to Many)
Seller
(PK) seller_id
(FK) seller_company_id
seller_code
Relationship: Company (to One)
My code successfully gets a Company object from the database (referred
to as import_Company below). It also retrieves a String called
source_code to compare with the Seller object's seller_code to help
narrow the search.
What I want is essentially an object from Seller where
(seller_company_id == import_Company.company_id) and (seller_code ==
source_code)
I have looked high and low for an example of the "WebObjects Way" to do
this. Most all of the specific EOQualifier and FetchSpec examples are
about following a relationship to some value employee.department.name
etc. I was good and did NOT include Primary or Foreign Keys accessors
in my Java Class files.
I could do NSArray SellerArray = (NSArray)import_Company.Sellers();
and then search each array element for the source_code == seller_code
match I'm looking for, but there must be a better way. I have tried to
adapt some of the examples I managed to find, but naming conventions
were not good enough to help me figure out if they were passing
relationships or something else. I have tried
filteredArrayWithQualifier and objectMatchingValues with no success.
Thanks for bailing out the newbie,
Scott
The standard format used in java programming is uppercase class names
eg) Seller and Company. Methods and variables start with a lowercase
character and use camel notation. eg) company, sellers, sellerCode,
companyName, etc.
You can probably use something like the following to achieve your goal.
aSellerCode; //assume exists
aCompany; //assume exists
NSMutableArray quals = new NSMutableArray();
quals.addObject(new EOKeyValueQualifier("sellerCode", aSellerCode));
quals.addObject(new EOKeyValueQualifier("company", aCompany));
EOQualifier andQual = new EOAndQualifier(quals);
EOSortOrdering order = //assume exists.
NSArray sellers = fetch("Sellers", editingContext(), andQual, order);
Obviously you need to write the fetch method, and the
EOKeyValueQualifier requires an argument for equality.(which I left out
so it would fit on a single line).
regards
- shaun
_______________________________________________
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