0

I have this Symfony Recepciones class which is related to a Obras_Sociales_Recepciones class as my BaseRecepciones class claims:

   /* @method Recepciones          setRecepcionId()                       Sets the current record's "recepcion_id" value
    * @method Recepciones          setCuentaLaboratorioId()               Sets the current record's "cuenta_laboratorio_id" value
    * @method Recepciones          setCuentasLaboratorios()               Sets the current record's "Cuentas_Laboratorios" value
    * @method Recepciones          setObrasSocialesRecepciones()          Sets the current record's "Obras_Sociales_Recepciones" collection
    */
        abstract class BaseRecepciones extends sfDoctrineRecord
        {
            public function setTableDefinition()
            {
                $this->setTableName('Recepciones');
                $this->hasColumn('recepcion_id', 'integer', 4, array(
                     'type' => 'integer',
                     'fixed' => 0,
                     'unsigned' => true,
                     'primary' => true,
                     'autoincrement' => true,
                     'length' => 4,
                         ));
                $this->hasColumn('cuenta_laboratorio_id', 'integer', 4, array(
                     'type' => 'integer',
                     'fixed' => 0,
                     'unsigned' => true,
                     'primary' => false,
                     'notnull' => true,
                     'autoincrement' => false,
                     'length' => 4,
                     ));
            }
        
            public function setUp()
            {
                parent::setUp();
                $this->hasOne('Cuentas_Laboratorios', array(
                     'local' => 'cuenta_laboratorio_id',
                     'foreign' => 'cuenta_laboratorio_id'));
        
                $this->hasMany('Obras_Sociales_Recepciones', array(
                     'local' => 'recepcion_id',
                     'foreign' => 'recepcion_id'));
            }
        }

however... when I do this on an action

$recepcionPrueba = new Recepciones();
$recepcionPrueba->setObrasSocialesRecepciones($myObject);

it says:

Unknown record property / related component "obras_sociales_recepciones" on "Recepciones"

any ideas?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Maruccio
  • 509
  • 1
  • 6
  • 14

4 Answers4

5

I finally discovered what happened, i hope it helps someone save the two or three days it took me to figure this out.

Doctrine 1.2 accepts only two types of notations for table names

CamelCase Or underscored_notation. Internally it recognizes any of them and its able to transform the former to the latter and vice-versa .

In my case if my table name was called "obras_sociales_recepciones" or "ObrasSocialesRecepciones" this error would've never ocurred.

the thing is that in Doctrine 1.2 you should never use a mix of CamelCase AND underscore notation, this is in my example Obras_Sociales_Recepciones, this absolutely confuses the ORM and you might recieve this strange error and never find out why!

Maruccio
  • 509
  • 1
  • 6
  • 14
  • The same problem was: table name was "amount_cur", but Doctrine wanted to get access to table "amount_CUR" but couldn't (table name was formed dynamically). Thanks! – Chaki_Black Feb 14 '14 at 12:55
0

Just a guess, as I'm a Propel user... would it help to move the parent::setUp() to the end of the setUp method? I am wondering if the parent does something with the relations, and is unable to if you define them after calling the parent.

halfer
  • 19,824
  • 17
  • 99
  • 186
0

Avoid using plural names when choosing your model name (in your case, you should use Recepcion). Could you post the comment that is located just before the BaseRecepciones ? The good method name is supposed to be in this comment, I guess it is something weird like setObrasSocialesRecepcioness() with 2 's'

greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • Still you should really really switch to singular names. See this thread : http://stackoverflow.com/questions/4100489/table-naming-convention-with-doctrine-orm and this one : http://stackoverflow.com/questions/6244615/naming-convention-singular-vs-plural-for-classes-describing-entities-in-php – greg0ire Nov 07 '11 at 21:50
0

It's a one to many so you don't do:

$recepcionPrueba->setObrasSocialesRecepciones($myObject);

You do

$recepcionPrueba->addObrasSocialesRecepciones($myObject);

You call 'set' on a one-to-one.

Flukey
  • 6,445
  • 3
  • 46
  • 71