Re: help needed with query
Re: help needed with query
- Subject: Re: help needed with query
- From: David Avendasora <email@hidden>
- Date: Mon, 4 Feb 2008 10:49:20 -0500
As Chuck Hill is fond of saying: "The Database is an artifact of
implementation"
The only time you should normally have to deal with things like
Foreign Keys, Primary Keys and such is making sure they are defined
right in the model. NOT in code.
If the model is setup right, you should simply be able to setup a
fetch request either in the model, or in code that states:
instanceOfNames.valueForKeyPath("namesbusinssmeta.iscurrent") = "true"
In code you can do it this way (written from memory, it's possible
thar bugs be here):
public NSArray namesWithCurrentMetadata() {
EOEditingContext ec = session().defaultEditingContext();
NSMutableArray args = new NSMutableArray();
args.addObject("true");
EOQualifier qual = EOQualifier.qualifierWithQualifierFormat
("namesbusinessmeta.iscurrent = %@", args)
NSMutableArray sortOrderings = new NSMutableArray();
EOSortOrdering sortOrder = new EOSoertOrdering
("lastName",EOSortOrdering.CompareAscending);
sortOrderings().addObject(sortOrder);
EOFetchSpecification fs = new EOFetchSpecification("names", qual,
sortOrderings);
return ec.objectsWithFetchSpecification(fs);
}
I found the book "WebObjects for mac OS X" by Joshua Marker to be
very valuable for learning how to setup fetch specifications in both
the model and in code and all the various things you can do with them.
Also, don't have a trigger to create a record in the
namesbusinessmeta. WO will do this automatically for you when you
submit namesbusniessmeta and set it as related to names. If it is a
business rule that every names (person) has at least one record in
namesbusinessmeta? If so, enforce it in the model, not in the DB with
a trigger. Having the DB do this will confuse matters and you may end
up stepping on yourself.
You are fighting WO. Sit back and let it work for you.
Now, on a side note, your table naming is somewhat confusing.
"names" really shouldn't be plural because it becomes confusing when
looking at the reverse relationship from namesbusinessmeta because
the relationship is singular, but it is going to have (by default) a
plural name. Besides, I'm guessing you really aren't storing
information about Names, you are storing information about People -
names generally don't have phone numbers and such, _people_ do.
Dave
On Feb 4, 2008, at 8:57 AM, Theodore Petrosky wrote:
First, most of my experience is with cocoa. I could
write any query I wanted even across relationships. I
am having a problem with relationship in WO.
I am starting out with a new simple setup. My db is
normalized like this
table names:
firstname text
lastname text
nameid (serial)
namesbusinessmeta:
iscurrent bool default true
phonenumber text
extension text
nbmid
namesFKid foreign key to names
I have a trigger and function on the db that creates a
new insert into namesbusinessmeta with the referenced
foreign key on insert into the names table.
This works fine.
but now I want to query from my WO app.
select * from names where nameid in (select namesFKid
from namesbusinessmeta where iscurrent = true) order
by lastname;
I am lost.... I want an array of current employees
where the iscurrent bool is in relationship table.
Maybe I am barking up the wrong tree......
Ted
______________________________________________________________________
______________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/
newsearch/category.php?category=shopping
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40avendasora.com
This email sent to 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