Table where primary key is also foreign key


Author
Message
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, if you're using the PrimaryKeyIsAutoIncremented = True on the business object, then there is a method on the BO called GetPostSavePrimaryKeyValue() that will retrieve the auto-assigned pk value for the specified pre-save primary key value (i.e. if you pass -3, it will pass back something like 57 that matches the value on the server).  So, you would need to save, then in the AfterSave event, cycle back through the BO and on each record that has a negative value for the foreign key, get the proper value and resave it after you set all of them to the proper values.  If you're not using the auto-assigned PKs, then you don't have to worry about it because the PK will be the same in the BO as on the server Wink
Marcel Heitlager
Marcel Heitlager
StrataFrame User (274 reputation)StrataFrame User (274 reputation)StrataFrame User (274 reputation)StrataFrame User (274 reputation)StrataFrame User (274 reputation)StrataFrame User (274 reputation)StrataFrame User (274 reputation)StrataFrame User (274 reputation)StrataFrame User (274 reputation)
Group: StrataFrame Users
Posts: 84, Visits: 835
Any recommendations on how to deal with the following scenario (this is a representation of what I'm trying to accomplish)?

A supervisor is an employee and an employee can be a supervisor.  Also certain employees can work under certain supervisors. All employees have a supervisor. So you would have a table that might look like this:

employeeKey  last_name  supervisorKey
1                  smith        1
2                  johnson     1
3                  smithers    1
4                  chase       4
5                  baker        4
6                  brown       1

If supervisor key = employeekey then the employee is the supervisor.

How would you handle it when, for example, you are entering new employees and supervisors on a grid, on an autoincrementing table (like vfp - which I got to work with your Bo's) and you do a batch save?  I would need to know the employeeKey in order to apply a value to supervisorKey. Can this be handled with one business object, or would it be best to just create two business objects one for employees, one for supervisors and save the supervisorsBO first, pull the employeekeys, apply them to supervisor key in employeeBO and then save employeesBO to same table?

I've been racking my brains about this.  Thanks in advance for any input.

Marcel

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search