Table where primary key is also foreign key


Author
Message
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

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
Jéssica Neves
Jéssica Neves
StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)
Group: Forum Members
Posts: 14, Visits: 102
hi everyone!
I wonder how I Faso to obtain planning the value of a search field in the browser dialog manually
I'm using the event SearchValueChange
i wanted to get the primary key of the selected field
example
name - Jessica ID - 5
 
I use?
browseDialog.SearchFields.GetValues() ;

?

Edited 15 Years Ago by Jéssica Neves
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Jessica,

I don't quite understand you need, but if all you want is to get a value entered by the user in the BD, then here is a sample code I use in one of my Browse Dialog subclass:

  Private Sub ServiceCallsBrowserDialog_SearchValueChanged(ByVal sender As System.ObjectByVal e As MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogSearchValueChangedEventArgsHandles Me.SearchValueChanged
            '-- When a customer is selected form the combobox, then requery the Building combobox.
            If e.SourceSearchField.Key.Equals("FK_Customers"StringComparison.OrdinalIgnoreCase) Then
                Dim comboListPopulationParam1 As Integer = 0

                '-- If the customer combobox has any selected record, then update the 
                '   comboListPopulationParam1 with the Customer PK
                If CType(e.SourceControl, ComboBox).SelectedIndex > 0 Then
                    '-- Resize the combo to properly show its information.
                    e.AllVisibleSearchControls("FK_Buildings").Width = 300

                    comboListPopulationParam1 = CType(e.SourceControl, ComboBox).SelectedValue
                End If

                '-- Requery the Building Address combobox.
                CType(e.AllVisibleSearchControls.Item("FK_Buildings"), ComboBox).Requery(comboListPopulationParam1, MicroFour.StrataFrame.Business.BusinessEditingState.Idle)
            End If
        End Sub


As you can see, this sample shows you how to read a value and how to set another one in the BD.  If I misunderstood you please clarify.

Edhy Rijo

Jéssica Neves
Jéssica Neves
StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)
Group: Forum Members
Posts: 14, Visits: 102
na verdade é assim !

quando o usuario final escolher seu campo no browserdialog

vai entrar no evento 

"SearchValueChanged"

ai eu quero fazer uma variavel receber a Primary key do campo escolhido pelo usuario.

eu não estou usando combobox...

BigGrin


Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Sorry but I don't read/speak Portuguese Hehe  I truly love the language, know some music artist from Brazil,  very well known here in America like Nelson Ned, Alexander Pirex, Roberto Carlos and of course the must famous one, the SF Googleish Ivan Tongue

Please, post in English so I can follow.

Edhy Rijo

Jéssica Neves
Jéssica Neves
StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)
Group: Forum Members
Posts: 14, Visits: 102


in fact it is so!

when the End User choose their field browserdialog

will enter the event

"SearchValueChanged"

then I want to make a variable to receive the Primary key field chosen by the User.

I'm not using combobox ...

sorry my english, I'm beginner.

Edited 15 Years Ago by Jéssica Neves
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Jéssica Neves (10/25/2010)
in fact it is so!
when the End User choose their field browserdialog will enter the event "SearchValueChanged" then I want to make a variable to receive the Primary key field chosen by the User. 


Jessica, that is exactly what my code is doing, checking if the field that triggered the SearchValueChanged is "FK_Customers", then using the e.SourceControl you cast that to your control type and access the value you need from whatever property your control is using.

Now what do you want to do with this value?

sorry my english, I'm beginner.

Well it looks much better than my Portuguese Whistling

Edhy Rijo

Jéssica Neves
Jéssica Neves
StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)
Group: Forum Members
Posts: 14, Visits: 102
Thank!!!Tongue

Edhy Rijo

listen to these bands Luan Santana,Jorge Matheus ,

I hope you enjoy
Edited 15 Years Ago by Jéssica Neves
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Jéssica Neves (10/25/2010)
listen to these bands Luan Santana,Jorge Matheus ,

I hope you enjoy


You are welcome Jessica, will look for those. 

Hey Ivan what do you think about these bands? Cool

Edhy Rijo

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