Use of __isa__ and primary keys

A place for users and developers of the Xataface to discuss and receive support.

Use of __isa__ and primary keys

Postby rdb » Wed Feb 25, 2009 11:24 am

I have a question about the use of the "__isa__" directive in the "fields.ini" table. What is the best (or typical) way to fill the primary key field of the context (child) table when the parent table primary key is "auto-increment"-ed? The docs almost implies that XF takes are of this. However when I try to insert a new record, I get an error message that the primary key of the child table "is required", implying that it isn't getting filled.

Here is the details of what I did:

I'm implementing a database where I'm keeping records of people of different classes; faculty, staff, and students. These classes share some attributes (last name, first name, phone number, email address, etc.), but not others (faculty have "teaching interests" but students and staff don't, students have a "thesis defense date" but faculty and staff don't, and so on). To me, this looks like a classic case for implementing inheritance. So I decided to take advantage of the "__isa__" directive. I created "people" and "faculty_profile" tables as follows:

CREATE TABLE IF NOT EXISTS `people` (
`id` int(11) NOT NULL auto_increment,
`given_names` varchar(64) NOT NULL default '',
(... yada, yada, yada ...)
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `faculty_profile` (
`people_id` int(11) NOT NULL,
`teaching_interests` text,
(... yada, yada, yada ...)
PRIMARY KEY (`people_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Then I created the field.ini and valueslists.ini for both tables and inserted "__isa__=peope" into the fields.ini file in tables/faculty_proifle. Finally, I updated conf.ini with a faculty=Faculty record under [_tables]

As a test, I manually (i.e., carefully handcrafted, using only the finest ingredients) a record in each of the two tables, updating the faculty.people_id field with the corresponding people.id value. Then I opened the record in XF (things looked good), made a change and saved the data. It worked.

However, if I try to add a record, I get the following error upon clicking Save:
Code: Select all
Invalid information entered.
- People id is a required field.
Please correct these fields.


So it appears the faculty_profile.people_id field is not getting filled.

I can't fill the faculty_profile.people_id field until the people.id field is filled, and that field doesn't get filled until the record is inserted into the database because it is "auto_increment". But, the record can't be inserted into the database until the faculty_profile.people_id field is field. Classic Catch 22.

I'd appreciate any thoughts or enlightenment on this. Thank-you.
- -
rdb
rdb
 
Posts: 10
Joined: Wed Feb 25, 2009 10:17 am
Location: Burnaby, BC

Version info

Postby rdb » Wed Feb 25, 2009 11:27 am

BTW, I'm using:
Dataface 1.0.7 561
mysql 5.0.45-7
Red Hat Enterprise Linux 5
- -
rdb
rdb
 
Posts: 10
Joined: Wed Feb 25, 2009 10:17 am
Location: Burnaby, BC

Postby shannah » Thu Feb 26, 2009 12:30 am

I'm going to have to look into this one. May be a bug as I haven't used inheritance in a while....
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

WORKAROUND FOUND - Use of __isa__ and primary keys

Postby rdb » Mon Mar 16, 2009 12:06 pm

I think I've found a couple of workarounds for this problem:

1. allow the foreign key field of the context (child) table to be null, or

2. set the default value of the foreign key field of the context table to some non-null value. XF seems to over-write it with the contents of the foreign key field(s) in the parent table anyways, so it can be set to anything.

I've done some testing and it seems to solve the problem. I have not fully regression tested it (and likely won't), so your mileage may vary.

I must say that I accidentally stumbled across the __isa__ feature, and am so glad I found it. Inheritance is a powerful data modeling tool and this feature has saved me from the hassle of having to implement it manually! Nice work, Steve!
- -
rdb
rdb
 
Posts: 10
Joined: Wed Feb 25, 2009 10:17 am
Location: Burnaby, BC

Postby shannah » Tue Mar 17, 2009 3:21 pm

Thanks for the notes on the workarounds. I haven't used the __isa__ feature in a while so I have to admit that I'm a little rusty on the details of it. Glad to know you got it working.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 12 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved