【问题标题】:yet another Unknown record property / related component另一个未知记录属性/相关组件
【发布时间】:2011-11-04 21:04:13
【问题描述】:

我有这个 Symfony Recepciones 类,它与我的 BaseRecepciones 类声称的 Obras_Sociales_Recepciones 类相关:

   /* @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'));
            }
        }

但是......当我在一个动作上这样做时

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

上面写着:

“Recepciones”上的未知记录属性/相关组件“obras_sociales_recepciones”

有什么想法吗?

【问题讨论】:

    标签: model doctrine symfony1


    【解决方案1】:

    我终于发现了发生了什么,我希望它可以帮助我节省两三天的时间来解决这个问题。

    Doctrine 1.2 只接受两种类型的表名表示法

    CamelCase 或 underscored_notation。在内部,它可以识别其中的任何一个,并且能够将前者转换为后者,反之亦然。

    就我而言,如果我的 表名 被称为“obras_sociales_recepciones”或“ObrasSocialesRecepciones”,则永远不会发生此错误。

    问题是,在 Doctrine 1.2 中,您应该永远不要混合使用 CamelCase 和下划线表示法,这在我的示例中是 Obras_Sociales_Recepciones,这绝对会混淆 ORM,您可能会收到这个奇怪的错误并且永远不会找出原因!

    【讨论】:

    • 同样的问题是:表名是“amount_cur”,但Doctrine想访问表“amount_CUR”但不能(表名是动态形成的)。谢谢!
    【解决方案2】:

    只是猜测,因为我是 Propel 用户...将 parent::setUp() 移动到 setUp 方法的末尾会有所帮助吗?我想知道父母是否对关系做了一些事情,如果您在调用父母后定义它们,则无法做到。

    【讨论】:

      【解决方案3】:

      在选择型号名称时避免使用复数名称(在您的情况下,您应该使用Recepcion)。您能否发布位于 BaseRecepciones 之前的评论?好的方法名应该在这个评论中,我猜这有点奇怪,比如setObrasSocialesRecepcioness() with 2 's'

      【讨论】:

      【解决方案4】:

      这是一对多,所以你不要这样做:

      $recepcionPrueba->setObrasSocialesRecepciones($myObject);
      

      你会的

      $recepcionPrueba->addObrasSocialesRecepciones($myObject);
      

      您一对一地调用“设置”。

      【讨论】:

      • 对不起,这不是解决方案,我只是添加了出现在函数签名之前的 cmets
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多