Re: Fetching from related object
Re: Fetching from related object
- Subject: Re: Fetching from related object
- From: Chuck Hill <email@hidden>
- Date: Mon, 26 Apr 2004 09:04:43 -0700
Anything in the CustView or Log constructor?
Override awakeFromFetch?
On Apr 26, 2004, at 7:03 AM, Randall Perry wrote:
I rebuilt my model from scratch just in case I had messed something up
with
it.
There are 2 tables I imported from an existing PostgreSQL db:
cust_view and
log, which EOModeler named CustView and Log.
CustView's pk is custNo. Log's pk is logNo and it has the foreign key
custno.
I created a relationship by using diagram view, control-dragging from
CustView custNo to Log custNo which created a to-many link from
CustView to
Log called 'logs', and a to-one link from Log to CustView called
'custview'.
Consistency check on model passes. I reimported the model and java
class
files to my project.
So I changed the fetch to this:
logInfo = (NSArray)custInfo.valueForKey("logs");
Again, it runs without error but returns an empty array.
Just to describe my project again: A static HTML page sends username,
password form values to a DirectAction in my project. The DA fetches a
single row from CustView which is used to authenticate. Then I need to
grab
associated log records for the cust, and that's where it's failing.
As I said in a previous post if I force a prefetch from the 1st fetch
on
CustView the above code returns a populated array:
custFetchSpec.setPrefetchingRelationshipKeyPaths(new
NSArray("Log"));
Don't know if the fact that I'm not using sessions and created my own
editing context has anything to do with this.
***********************************************************************
*
Here's a listing of the relevant code:
From DirectAction.java
----------------------
public WOActionResults loginAction() {
NSArray custInfo;
NSArray logInfo;
EOEditingContext ec = new EOEditingContext(); // create an
editing
context
String userName =
((String)request().formValueForKey("login")).trim();
// grab form values and trim
String passWord =
((String)request().formValueForKey("pass")).trim();
// set filter on query using userName and passWord vars passed
from form
EOQualifier qual =
EOQualifier.qualifierWithQualifierFormat("userName =
'" + userName + "' and password = '" + passWord + "'", null);
// create fetchSpec with qualifier
EOFetchSpecification custFetchSpec = new
EOFetchSpecification("CustView", qual, null);
// fetch cust record
custInfo = ec.objectsWithFetchSpecification(custFetchSpec);
// fetch associated log records
logInfo = (NSArray)custInfo.valueForKey("logs");
...
...
}
From CustView.java
------------------
public NSArray logs() {
return (NSArray)storedValueForKey("logs");
}
From Log.java
--------------
public CustView custview() {
return (CustView)storedValueForKey("custview");
}
on 4/25/04 7:40 PM, Arturo Pirez at email@hidden wrote:
Tried the code above:
logInfo = (NSArray)custInfo.valueForKey("Log");
It runs ok but returns an empty array.
Seems that the relationship is improperly defined. If your
relationships are improperly defined then WO/EOF will misbehave in all
sorts of really incredibly irritating and painful ways. Would you
care
to elaborate on those two tables and the EOF entities you've defined
on
them?
----
WO in philadelphia - wanna cheesesteak with that?
Please visit webobjects.meetup.com.
--
Randall Perry
sysTame
Xserve Web Hosting/Co-location
Website Development/Promotion
Mac Consulting/Sales
http://www.systame.com/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.