[CDBI] one to one relationship
brett gardner
brett at clientcomm.com.au
Tue Jun 13 06:07:11 BST 2006
What is the best way to define a one to one relationship in Class::DBI?
I have a table of queries where a user can do a basic search for
services. Then, if they want more information on their search, they can
fill in their details which populates a request. Nine times out of ten
the user will not be requesting any more info so I have created two
tables, "queries" and "requested_queries".
queries
-------------
| query_id |
| search |
| timestamp |
-------------
requested_queries
----------------------
| requested_query_id |
| query_id |
| firstname |
| surname |
| email |
----------------------
Now is there anyway in Class::DBI to setup a relationship whereby I
could code the following (for an existing query that does not yet have a
matching requested query)
$query->requested_query->create();
$query->requested_query->firstname('Joe');
$query->requested_query->surname('bloggs');
$query->requested_query->update();
I tried using "might_have", but this fails as both the "firstname" and
"surname" are required fields. And as soon as I call
"$query->firstname('joe');" it tries to run the insert statement without
waiting for the "$query->update" call.
Cheers
--
Brett Gardner
Clientcomm
Phone : 02 9699 1888
Fax : 02 9318 6499
More information about the ClassDBI
mailing list