Re: Database won't accept null foreign key
Re: Database won't accept null foreign key
- Subject: Re: Database won't accept null foreign key
- From: email@hidden
- Date: Tue, 07 Oct 2003 10:55:34 CDT
- Priority: 3 (Normal)
[demime could not interpret encoding binary - treating as plain text]
On Mon, 6 Oct 2003 20:49:42 -0400 Bob Stuart wrote:
> Albert,
> Another somewhat twisted approach is to create a row whose
> primary key is Zero and instead of setting the relationship to null
> set it to this dummy record. That will get WO to push Zero into the
> DB. After that you might do something to detect the relationship is
> pointing to the Zero record and do special processing for it.
There could be some added problems going on, because EOF often likes to
treat a 0 pk the same as a null pk. If you try to insert an EO with a
manually-set 0-value PK, EOF will complain that the row has no primary
key. It won't accept 0 as a valid primary key, it treats it the same as
null. This is a sort of weird Objective C legacy thing.
In this case, I'm not sure if it would hurt you, or help you, or be
irrelevant, since we're really talking about a foreign key, not a primary
key. But something to be aware of in case weird things start happening
that you can't explain.
I think I'd try a different approach: make the foreign key column
class-visible (the little diamond next to it in EOModeler). Hopefully,
doing this shouldn't mess up EOF's ordinary relationship-handling stuff.
I don't think it will---I don't think that the value of this fk
attribute, when examined in memory, will always match the primary key of
the in-memory relationship destination. But that's fine, don't ever look
at this value, and you won't mind that it gets out of synch. I _think_
EOF will still do everything else properly. But, making this a
class-visible property _might_ allow you to manually set it to 0, after
nulling out the relationship. Or it might not work.
It's going to be a pain to get this to work properly. I think you're just
going to have to play around with lots of different stuff until you
(hopefully) find something that works.
--Jonathan
> If you don't do this you will either have to check for the
> foriegn key being Zero and not traverse the relationship or you will
> have EOF creating dummy records with the zero key after a failed DB
> hit.
>
>
> At 3:38 PM -0500 10/6/03, Albert Jagnow wrote:
> >I am working with a database that for whatever reason won't allow a
> >foreign key to be null if the relationship does not exist. I am unable
> >to make any changes to the database setup. In this database table A may
> >have an optional one-one relationship with table B. If there is not
> >relationship or I delete a relationship, WO wants to set the foreign key
> >in table A for table B to null. The database won't allow the foreign
> >key column of table A to be null it wants it to be 0. Is there an easy
> >trick to get WO to generate 0 instead of null for that key if the
> >relationship does not exist?
> >
> >--Albert
> >
> >
> >This e-mail (including any attachments) is covered by the Electronic
> >Communications Privacy Act, 18 USC. 2510-2521. It is confidential and
> >may be legally privileged. If you are not the intended recipient, you
> >are hereby notified that any retention, dissemination, distribution, or
> >copying of this communication is strictly prohibited. Please reply to
> >the sender that you have received the message in error, and then delete
> >it. Thank you.
> >_______________________________________________
> >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.
>
>
> --
> Bob Stuart
> _______________________________________________
> 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.