Board index » delphi » Master/Detail Relationships, Database Design Issue, Newbie :)

Master/Detail Relationships, Database Design Issue, Newbie :)

I'm developing a multi-user database using Interbase and the (IBX) controls.
I am amazed at how easy everything seems to come together.  However, I am
having a few problems and I'd like to get a little input.

My database has two tables, Table1 and Table2.  Table1 contains information
on a students contact information, and Table2 contains information on the
students physical appearance.  Both tables have the same primary key
(Student_Number).  I use two TIBDatasets to browse and modify both tables,
with Table1's dataset setup to be the Master of Table2's dataset.  Browsing
works very well, without any code, I can use a DBNavigator connected to
Table1's TIBDataset's Datasource and both datasets scroll in unison.

And yes, Table1 and Table2 could definitely just be one table, but I'd like
to keep them separate if possible.

The problem comes when inserting.  If I click insert on the dbnavigator, it
only puts Dataset1 into Insert mode, NOT Dataset2.  Dataset2 doesn't go into
insert mode until I 'click' on a dbcheckbox (Dataset2 is linked only to
dbcheckboxes).  The problem with this is that if the user doesn't click on a
dbcheckbox linked to Dataset2 and hit's 'post' that record never gets
inserted into Dataset2.  So using my example, I would have a student in
Table1 that doesnt have a record in Table2.  I can't have this.

Could this be a flaw in my code?  Is a Master/Detail relationship designed
to work this way?  Or should Table1 and Table2 definitely just be one table?
I'm very new to the whole Master/Detail structure and I'd appreciate any
input.  It looks like I wouldn't have this problem if Table1 and Table2 were
just one table, but like I said I'd like to keep these Tables separate
because they store a different class of information.

Thanks.

 

Re:Master/Detail Relationships, Database Design Issue, Newbie :)


Quote
> The problem comes when inserting.  If I click insert on the dbnavigator,
it
> only puts Dataset1 into Insert mode, NOT Dataset2.  Dataset2 doesn't go
into
> insert mode until I 'click' on a dbcheckbox (Dataset2 is linked only to
> dbcheckboxes).  The problem with this is that if the user doesn't click on
a
> dbcheckbox linked to Dataset2 and hit's 'post' that record never gets
> inserted into Dataset2.  So using my example, I would have a student in
> Table1 that doesnt have a record in Table2.  I can't have this.

I'd rather call your case a Master/slave situation as you have a one to one
relation between the two tables.
In you case, I can suggest you to post only one dataset (Dataset1)
Then, add some code in DataSet1.OnAfterInsert event to test if DataSet2 is
in dsInsert mode, if not you can insert an empty record yourself.

DL

Other Threads