Remoting and reference

Posts   
 
    
bchebrou
User
Posts: 18
Joined: 14-Feb-2006
# Posted on: 14-Feb-2006 13:13:43   

Hi all,

I've a question about remoting and mutliple reference. Imagine i've two classes Person and Adress. Each person have only one address. So i've a relation between Personn and Adress. If 2 persons have the same address i want that, when i fetch the 2 persons, their adresses have the same reference. That's seems ok with the context on the server side. But when i passed my collection of person by remoting, is it possible that the addresses of my two clients have the same reference on the client side ? disappointed

Regards,

Ben.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Feb-2006 14:24:00   

If you want it that way, then you may want to Fetch a collection of Addresses with their related Person Entities. Other than Fetching Persons Entities with their related Addresses.

bchebrou
User
Posts: 18
Joined: 14-Feb-2006
# Posted on: 14-Feb-2006 14:49:22   

Thanks Walaa for your quick answer simple_smile

I see what you mean , but my real project is a little bit more complex that my sample...

If by example i've a Person with no address, with your method it will not be loaded... So if my goal is to have all my Persons on the client side with their address. And that all the addresses with the same PK on the client side have the same reference, is it possible ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Feb-2006 15:18:38   

I don't think it's possible.

But let me discuss this design with you, because it has faced me before.

1- I found that the best relation between Person & Address Entities is 1:1 relation not m:1

Let's examine having the case of 2 brothers living in the same house, what if one of them will move to a different address, then with your approach you may mistakenly change the Address of them both. Then having a 1:1 relation is a better approach IMHO.

2- One thing that I dislike in database applications is NULL values simple_smile so I always tend to use default values.

That's to say in your situation I'd create an Address Entity for a Person who have no Address defined yet, and I'd fill it up with default values ("N/A" for instance)

This also will make me only create a new Address when I'm creating a new Person in one Transaction, and never again, and delete an Address when I'm deleting a Person. I'll only have to think about Updating the Address when needed, and I'll be always sure that there is an Address record available for every Person.

That's my not be suitable for many developers, but this what I found to be the best design pattern for this situation.