strange one-to-one relationship

From: Tore Halset (halse..vv.ntnu.no)
Date: Wed Nov 19 2003 - 04:03:34 EST

  • Next message: Leonardo R. Nunes: "Date in SQLServer"

    Hello.

    My database has two tables that look like this. One car can have one
    engine and one engine can only be in one car.

    create table car (car_id int primary key, engine_id int);
    create table engine (engine_id int);

    That looks like a one-to-many, but the car.engine_id column has a unique
    index.

    I have defined this as a one-to-one relationship in cayenne modeler, but
    the relation from engine to car does not work. engine.getCar() does return
    one object, but all of the attributes are null.

    When I try to create a new database from cayenne modeler the following
    erromessage are given.

    "Schema Generation Error - Failed statement: ALTER TABLE engine ADD
    FOREIGN KEY (engine_id) REFERENCES car (engine_id) - ERROR: UNIQUE
    constraint matching given keys for referenced table car not found"

    I have worked around the problem by defining the relation from engine to
    car as a one to many relationship.

     - Tore.



    This archive was generated by hypermail 2.0.0 : Wed Nov 19 2003 - 04:03:35 EST