What to generate

Posts   
 
    
rblock avatar
rblock
User
Posts: 71
Joined: 13-Mar-2009
# Posted on: 06-Apr-2009 09:06:22   

Hi,

I'm not sure: Do I've to generate the code for the m:n relational tables to?

So e. g. I would have

CompanyCars Persons

and the m:n relational table

CarsPersons

because a Person as employe can use different cars at different times and each car of the company can be used by different employees at different times. Like a internal car rental.

So do I've to genereate Entity code for this CarsPersons table (in the case that there would be no more information as two foreign keys in it)? confused

Unsure greetings

Reiner

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 06-Apr-2009 11:21:04   

Yes, you should generate code for this. Every database table used should be mapped to be generated.

e.g. of usage: When you assign a car to an employee, this intermediate table should be used, a record should be inserted there.

rblock avatar
rblock
User
Posts: 71
Joined: 13-Mar-2009
# Posted on: 06-Apr-2009 11:26:39   

Hi Walaa,

Walaa wrote:

e.g. of usage: When you assign a car to an employee, this intermediate table should be used, a record should be inserted there.

hm, so I misunderstood the documentation because I thought, that if e. g. I load an existing and persisted Person, add a new Car and use Save(true) for update the person, the new Car relation will be saved automatically, too?

Now I am more confused. confused confused

VeryConfused greetings

Reiner

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 06-Apr-2009 11:49:25   

Please read the last example ("How do I add an entity A to an entity B's collection of A's if A and B have an m:n relation ?") in the following documentation page.

This proves with no doubts that you need the intermedidate entity and you should explicitly use it in code to manage such m:n relation. Nothing is done automatically here.

rblock avatar
rblock
User
Posts: 71
Joined: 13-Mar-2009
# Posted on: 06-Apr-2009 12:15:37   

Hi Walaa,

thanks! That makes it clear to me. So what I'd in mind is just for 1:n or m:n relations. In my classes I've to add an Add() method or something like that in order to handle those m:n relations, isn't it? simple_smile

Thankfull greetings

Reiner

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 06-Apr-2009 12:51:19   

Yes, the code shown in that example should be used in a BL method which performs the specified action.