0

I've this schema.yml file (just relevant part):

SdrivingMaquina:
  actAs: 
    Timestampable: ~
  columns:
    idmaquina: { type: integer(8), autoincrement: true, notnull: true, primary: true }
    idempresa: { type: integer(4), notnull: true }
    patente: { type: string(12), notnull: true }
  relations:
    Empresa: { local: idempresa, class: SdrivingEmpresa, type: one, foreignType: one, foreignAlias: MaquinaEmpresa, onDelete: CASCADE, onUpdate: CASCADE }
SdrivingMaquinaEmisor:
  actAs: 
    Timestampable: ~
  columns:
    idmaquinaemisor: { type: integer(8), primary: true, autoincrement: true }
    idmaquina: { type: integer(8), notnull: true }
    idemisor: { type: integer(8), notnull: true }
  relations:
    SdrivingEmisor: { onDelete: CASCADE, local: idemisor, foreign: idemisor, type: one }
    SdrivingMaquina: { onDelete: CASCADE, local: idmaquina, foreign: idmaquina, type: one }

Then after I run the task symfony doctrine:build-model I check the class BaseSdrivingMaquina.class.php and I can see this code:

public function setUp()
    {
        parent::setUp();
        $this->hasOne('SdrivingEmpresa as Empresa', array(
             'local' => 'idempresa',
             'foreign' => 'id',
             'onDelete' => 'CASCADE',
             'onUpdate' => 'CASCADE'));

        $this->hasOne('SdrivingEmpresa', array(
             'local' => 'idempresa',
             'foreign' => 'idempresa'));

        $this->hasMany('SdrivingMaquinaEmisor', array(
             'local' => 'idmaquina',
             'foreign' => 'idmaquina'));

        $timestampable0 = new Doctrine_Template_Timestampable();
        $this->actAs($timestampable0);
    }

When I try to insert any record I get this error:

Couldn't call Doctrine_Core::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references.

Which make me think that the error is the relation. This post is related to this one can any tell me what's wrong or where is my mistake?

Community
  • 1
  • 1
Reynier
  • 2,420
  • 11
  • 51
  • 91
  • An example of the code that is generating the error would be useful. – moote Jun 25 '13 at 16:34
  • @moote the code is in the related post, take a look at there (for not repeat the same here) – Reynier Jun 25 '13 at 18:39
  • It's many-to-one because it's the default these kind of relations. Is it correct or you want one-to-one? (write `SdrivingMaquina: { onDelete: CASCADE, local: idmaquina, foreign: idmaquina, type: one, foreignType: one }` then) Sorry, but it's really hard to understand your example code as it's not in english and not uses conventions, but maybe it's just me... :) – 1ed Jun 25 '13 at 20:28
  • @1ed yes I want one-to-one and what's the difference between this `SdrivingMaquina: { onDelete: CASCADE, local: idmaquina, foreign: idmaquina, type: one, foreignType: one }` and what I've? Or you mean remove the `SdrivingEmisor` relation? – Reynier Jun 25 '13 at 20:48
  • `foreignType: one` at the end :) ... and by the way the two `$this->hasOne('SdrivingEmpresa ...)` relation looks very suspicious to me... maybe you should check that too. – 1ed Jun 25 '13 at 20:56
  • @1ed don't know why `$this->hasOne('SdrivingEmpresa ...)` but after correct the error of `foreignType: one` things are working, the problem now is when I try to edit the saved values but this is another post – Reynier Jun 25 '13 at 21:50

1 Answers1

1

To have a one-to-one relation you should write

SdrivingMaquina: { onDelete: CASCADE, local: idmaquina, foreign: idmaquina, type: one, foreignType: one }

so add the foreignType: one parameter.

1ed
  • 3,668
  • 15
  • 25