Re: Duplicate entry [ was addObjectsToBothSide... not really both side]
Re: Duplicate entry [ was addObjectsToBothSide... not really both side]
- Subject: Re: Duplicate entry [ was addObjectsToBothSide... not really both side]
- From: Chuck Hill <email@hidden>
- Date: Thu, 28 Sep 2006 11:04:58 -0700
On Sep 27, 2006, at 4:23 PM, Dev WO wrote:
Hi,
I though everything was good with my oneToOne (pk to pk)
relationship, but not completely in fact.
So A and B have a relationship joining their pk.
But B can be "alone", which means I can have B object without A
object.
Well, that won't work. With a PK to PK relationship, EOF expects
that both will always exist. You can sort of work around this by
making the optional one a to-many and then adding cover methods like
public A a() {
return (toAs().count() > 0) ? return (A)toAs().objectAtIndex(0) :
null;
}
So it happens that sometimes, when creating a A object (which will
create the B object at the same time as the relationship is
created) and trying to save it, A got a primary key already used by
B which lead to a crash...
Is there a way to get the primary form the B object instead of the
A object? (B pks are always good as I cannot have an A object
without a B)
Yes, but that still leaves you with EOF thinking that it has a valid
reference to an A object when it does not.
Chuck
I've setup my onetoone on both pk and everything is good:)
Thanks a lot:)
I'll wait for tomorrow for the next question;)
Xavier
You really need to set both directions - EOF will not do it for you.
On Sep 26, 2006, at 3:38 PM, Dev WO wrote:
Hi zak,
Dev WO wrote on 9/25/06 1:26 PM:
So this one is a oneToOne relationship, with is specified in both
entities A and B.
[...]
A and B have a foreign key to each other, but only A gets
it... B's
foreign key stay "null".
I think you may not be modeling the relationship correctly. If you
really want a 1-to-1, A and B should share the same primary key
and A
should be propagating its primary key to B.
If both tables have their own primary keys, and both have
foreign keys
to each other, things don't really stand up from a relational
logic
point of view because you actually have two relationships -- A
is joined
to B by by A.b_id and B is joined to A by B.a_id.
Assuming that A.setB() is defined in terms of A.b_id, the
reason B.a_id
doesn't update is that B.a() is defined by B.a_id but the
relationship
you just set is defined by A.b_id. You have two separate
relationships
based on two separate keys.
HUUUUUU I feel stupid...not the first time though, and probably
not the last one too;)
In my case, B can exist alone (without any A to relating to it),
but A cannot exist alone, it must be linked to a B.
Does this change anything?
I'll try to make the relationship between pks.
Thanks:)
Xavier
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40anderhome.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:
40anazys.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:
40global-village.net
This email sent to email@hidden
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems. http://www.global-village.net/products/practical_webobjects
_______________________________________________
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