db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TP R Murthy <r.mur...@ceruleaninfotech.com>
Subject one-to-one bidirectional relationship
Date Tue, 30 Sep 2003 04:31:00 GMT
Hi,

I have been using torque for the past 3 months. i have come across a 
situation where, i would like to use a one-to-one bidirectional 
relationship. 

customer (
  id   integer(11) not null autoincrement,
  fname  varchar(50) not null,
  lname  varchar(50) not null,
  email  varchar(80) not null,
  homeAddress  integer(11) references address(id),
  officeAddress integer(11) references address(id)
);

address (
  id  integer(11) not null autoincrement,
  customer  integer(11) references customer(id),
  street1  varchar(50) not null,
  street2  varchar(50),
  city     varchar(50) not null,
  state    char(2) not null,
  country  varchar(50) not null
);

How could i insert into these tables with torque. If i had Customer object 
to model customer table and Address object to model address. There would 
have getAddress() and getCustomer() respectievly. 

problem is with the insert. if i inserted into customer table with 
customer.save(), it would throw an exception saying the constraint failed 
because it would try to insert 0 into homeAddress and officeAddress. i 
would have to have an extra method to prepare the criteria and set those 
two fields to null instead of 0. Same for the other way around. 

i was wondering of anyone knew the best way to do this. Should i change 
the DB structure or what. 

Any help in this direction is appreciated. 

regards,
Murthy
  

-- 
_________________________________________________________________
TP R Murthy (Systems Analyst)
Cerulean Information Technology Pvt. Ltd.
#24, floor#2, 5th Main, 5th Block, Koramangala, Bangalore-560 095.
Phone: 299-1886, 299-1897
Mobile: 98451 14346
web:http://www.ceruleaninfotech.com
_________________________________________________________________
   
    "We can easily forgive a child who is afraid of the dark. 
       The real tragedy of life is when men are 
          afraid of the light."
    
    -- Plato


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message