Re: mutually exclusive 1-to-0 or 1 relationship modeling
Re: mutually exclusive 1-to-0 or 1 relationship modeling
- Subject: Re: mutually exclusive 1-to-0 or 1 relationship modeling
- From: Miguel Arroz <email@hidden>
- Date: Fri, 14 Jan 2011 21:50:19 +0000
Hi,
I'm a little paranoid, but I would also look into writing a constraint in the DB (if possible) to force that, just in case. Depending on what you are doing, weird concurrency situations may lead to situations that were not supposed to be. By writing a DB constraint, you have a guarantee that your data will not corrupt, whatever happens above the DB. You can check for EOGeneralAdaptorExceptions for constraint errors, if you want.
Regards,
Miguel Arroz
On 2011/01/14, at 19:31, Michael Gargano wrote:
> See that's what I think I'm doing wrong. I need to throw out my minimalistic DB design instincts. No PFK's!!! Bad, Bad, Bad!!!!
>
> Thanks Kieran and Ramsey.
> -Mike
>
>
> On Jan 14, 2011, at 2:27 PM, Kieran Kelleher wrote:
>
>> You need to add foreign keys and don't propagate. Let EOF assign PKs as usual
>>
>> Regards, Kieran.
>> (Sent from my iPhone)
>>
>>
>> On Jan 14, 2011, at 1:04 PM, Michael Gargano <email@hidden> wrote:
>>
>>> The only question I have on this method is how do I propagate the primary key now? If the modeler thinks it's a 1-to-many I can't check that box. That's how this started to begin with. I had them set as one-to-manies, but I didn't know how that pk should be propagated in code.
>>>
>>>
>>> On Jan 14, 2011, at 11:45 AM, Kieran Kelleher wrote:
>>>
>>>> one-to-one relationships can only be mandatory, and EOF *automatically* creates the B and C when you create A and propogates the primary key (a setting in the EOModel BTW) from A to B and A to C.
>>>>
>>>> The only way to set up an optional "1-to-1" is to create a 1-to-many in EOF,
>>>>
>>>> A <-->> B
>>>> A <-->> C
>>>>
>>>> and put methods in A to get and set singular B or C, returning null when empty toMany array.
>>>>
>>>> Enforce the zero or one count on the relationship in the database by making the foreignkey of A a unique index in tables B and C.
>>>>
>>>> The mutually exclusive rule can be checked in validateForSave.
>>>>
>>>> YMMV,
>>>>
>>>> Kieran
>>>>
>>>> On Jan 14, 2011, at 11:16 AM, Michael Gargano wrote:
>>>>
>>>>> I have three entities A, B, and C...
>>>>>
>>>>> A has a 1-to-0 or 1 with B
>>>>> and
>>>>> A has a 1-to-0 or 1 with C
>>>>>
>>>>> An entry in A either has an entry in B or an entry in C. The two are mutually exclusive. When I try to set this up in the modeler it gives me some problems. Once I set a relationship as a one-to-one, the modeler won't let me select optional if optional is already unselected and the modeler generates a warning about having optional set if I edit the plist directly. I'm not sure if I'm doing this correctly, but it looks to me like the modeler isn't allowing 1-to-0 or 1 relationships.
>>>>>
>>>>> So, if I just live with the warnings...
>>>>>
>>>>> If I set the relationship between A and B and set the relationship to C to null (again because B and C are mutually exclusive), when I save changes it throws an exception complaining that all the properties in B are null. Anyone else doing something like this?
>>>>>
>>>>> Thanks.
>>>>> -Mike
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>
>
> _______________________________________________
> 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