1:1 Relationships

Posts   
 
    
Sam avatar
Sam
User
Posts: 95
Joined: 30-Jun-2004
# Posted on: 17-Nov-2004 22:10:53   

I have two tables: Employee

empid (and some other stuff)

1 2 3 Supervisor supid empid


snom 1 ssnd 2 jsldk 3 I have identified empid as a foreign key in the Supervisor table as well as defied it as a unique index. So I have a 1:1 relationship right? I have a key on both ends in my SQL Server diagram and a Supervisor - Employee (1:1) under Relations in the Project Explorer in LLBLGen. My question is why when I is EmployeeEntity.Supervisor return a Entity Collection rather than an Entity? What I am trying to achieve is getting somebody's supid when I know there empid. Any ideas? PS I am using the adapter method.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Nov-2004 10:38:54   

Define a unique constraint, not a unique index. Indexes are used to tune database engines, constraints are used to define relational model specifics.

These things are different, as a DBA can decide to remove an index because of database performance issues, but he can't remove a constraint because that's part of the relational model simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Sam avatar
Sam
User
Posts: 95
Joined: 30-Jun-2004
# Posted on: 18-Nov-2004 19:04:42   

I have defined it as a unique constraint not an index and regenerated the code. The project explorer shows a 1:1 relationship. But Employee.Supervisor still wants to return and Entity Collection. Am I not doing this right? All I want is an employees supervisorid form the supervisor table. Both tables have employeeid and a 1:1 relation ship. I have an employee entity and wast their supervisorid if it exits? cry

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Nov-2004 23:04:02   

Sam wrote:

I have defined it as a unique constraint not an index and regenerated the code. The project explorer shows a 1:1 relationship. But Employee.Supervisor still wants to return and Entity Collection. Am I not doing this right? All I want is an employees supervisorid form the supervisor table. Both tables have employeeid and a 1:1 relation ship. I have an employee entity and wast their supervisorid if it exits? cry

Hmm. that's very odd.. If the relation is 1:1, the property should return a single instance.

Please generate the code in a new, empty directory and check it, perhaps the generator doesn't overwrite your current code because the files are not checked out/read only etc... . If that also gives teh wrong results, please mail the project (llblgen pro .lgp file) to support@llblgen.com and I'll try to look at it a.s.a.p.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-Nov-2004 15:27:19   

Ok, this is a small issue, I'll answer it here, so others who might run into this, will know the answer right away simple_smile

Your employee table has a relation with supervisor, which is an 1:1 relation. The employee table also has an m:n relation with supervisor via the ExpenseReport entity.

The field mapped on the 1:1 relation is Supervisor_ and the field mapped on the m:n relation is Supervisor. (these names are chosen automatically, you can specify a suffix for fields mapped on relations which return a collection, in the project properties). So the fix is obviously: rename the field Supervisor, which is mapped on the m:n relation, into Supervisors and rename the field Supervisor_ into Supervisor, regenerate the code and all is well simple_smile

Frans Bouma | Lead developer LLBLGen Pro