Re: Stupid Relationship question.
Re: Stupid Relationship question.
- Subject: Re: Stupid Relationship question.
- From: "Tom Jones" <email@hidden>
- Date: Tue, 27 May 2008 11:27:43 -0500
Bahh!
Ken,
Thanks for the help, I looked at my database's structure and found it was not allowing the foreign key to be null. When I initially created the table, my EOModel did not have the supervisor relationship as optional, and I never updated my database.
Thanks again,
Tom
On Tue, May 27, 2008 at 11:12 AM, Ken Anderson <
email@hidden> wrote:
Tom,
It all depends on how your keys are setup. Can you give us a little more information on the relationship? For instance, do you have a supervisorId attribute in Employee that will be null ? If so, a fetch should not occur... it all depends on how the relationship is setup.
To EOF, if you have a value in a foreign key, then the related object MUST exist. This becomes a problem when you have (what I call) side-car tables, where the primary key of the sidecar is the same as the primary key of the main table. In this case, your foreign key is always non-null (since it's also your primary key), and therefore, EOF assumes the object exists. One way to work around this is to create a to-many relationship, call it 'supervisors', then have a custom method in your EO, 'supervisor', that returns NULL or the first object in 'supervisors'.
Ken
On May 27, 2008, at 11:55 AM, Tom Jones wrote:
So, I'm just playing around with WO, and decided t make an Organization Chart application. An employee has an optional to many relationship employee>>direct_reports, and an optional to one relationship employee>supervisor. The problem I have is when I try to display an employee who has no supervisor, I get an exception because when it tries to fetch the supervisor, it finds no matching record. My expectation was that it would return null, rather than raise an exception. What is the correct way to handle fetching optional relationships?
_______________________________________________
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
_______________________________________________
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