Re: A few basic questions about EOF
Re: A few basic questions about EOF
- Subject: Re: A few basic questions about EOF
- From: Chuck Hill <email@hidden>
- Date: Tue, 24 Mar 2009 14:49:52 -0700
On Mar 24, 2009, at 2:46 PM, Paulo Filipe Andrade wrote:
Hello Chuck,
On 2009/03/24, at 20:14, Chuck Hill wrote:
4 ==
Theoretically if a message has no relation to users, it should
be deleted.
Does Owns Destination work in this many-to-many scenario?
This doesn't sound right. If this relationship designates
messages that have been read by users, then you are saying that a
message that hasn't been read doesn't exist. While this is an
interesting philosophical idea, I don't think it really
translates into the real world. Can't you have unread messages?
This is unrelated to the read/unread messages. The idea is simple,
if a Message is no longer referenced by any User it should be
deleted.
So if userA and userB are the only ones that have a relation to
messageA
userA.removeObjectFromBothSidesOfRelationshipWithKey(messageA,
"messages");
userB.removeObjectFromBothSidesOfRelationshipWithKey(messageA,
"messages");
editingContext.saveChanges();
At this point messageA would be deleted.
There is no delete rule that will do this. I'd probably implement
this on Message:
public void removeFromUsers(User aUser) {
super.removeFromUsers(aUser);
if (users().count() == 0) {
editingContext().deleteObject(this);
}
}
You might find this problematic if the last user can be removed
then another one added. This opens up all sorts of interesting
concurrency problems.
Actually I've already solved this in my project. I asked this
because I found out about "Owns Destination" just a few days ago and
it got me wondering.
Basically I put a counter on Message marked for OL that serves as a
reference counting mechanism. Messages are related to Users on
creation, so I don't need to worry about the counter going up.
If two users unrelate themselves from a Message a the same time I
get an OL and try again. This way I can prevent "dangling" messages.
Yes, that should be fine. When the counter can go up again, then
things get more interesting. Miguel lives for those sorts of
problems. ;-)
Chuck
5 ==
Not directly related to this scenario but I still couldn't quite
figure out:
When doing a addObjectToBothSideOfRelationship how does EOF know
which relationship is the inverse relationship?
In Core Data this is explicitly set but not in EOF.
EOF is smart enough to look in the model and see that there is a
relationship on the destination that, in turn, has a destination
of the original object, therefore it must be the inverse.
Take the hypothetical case where there would be two relations back
to the source from the destination, what would happen then?
It looks for one that matches the join columns. I am not sure what
happens if you have two identical relationships, nor I am sure why
you would have two identical relationships.
Looking at the join columns makes sense. Thanks.
--
Chuck Hill Senior Consultant / VP Development
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