Pregunta

Los siguientes modelos:

class User extends Doctrine_Record {
    public function setTableDefinition() {
        $this->hasColumn ( 'iron', 'integer', 4 );
    }

    public function setUp() {
        $this->hasMany ('Field as Fields', array(
            'local' => 'id',
            'foreign' => 'owner_id'
        ));
    }
}

class Field extends Doctrine_Record {
    public function setTableDefinition() {
        $this->hasColumn('owner_id','integer',4);
        $this->hasColumn('ressource_id','integer',4);
        $this->hasColumn('ressource_amount','integer','2');
    }

    public function setUp() {
        $this->hasOne('User as Owner',array(
                'local' => 'owner_id',
                'foreign' => 'id'
        ));
    }
}

Y trato DQL siguiente:

$sqlRessourceUpdate = Doctrine_Query::create()
->update('Field f')
->set('f.Owner.iron','f.Owner.iron + f.ressource_amount')
->where('f.ressource_id = ?',1);

Resultados:

'Doctrine_Query_Exception' with message 'Unknown component alias f.Owner'

Básicamente, sólo quiero actualizar el atributo de "hierro" del campo-propietario según el valor de los campos de los

¿Fue útil?

Solución

Estoy adivinando que no se puede hacer referencia a otros cuadros como el de la consulta.

Esto puede no ser la mejor manera, pero aquí es lo que hago

$q = Doctrine_Query::create()
    ->select('*')
    ->from('Field')
    ->where('ressource_id = ?',1); //btw resource has one 's'

$field = $q->fetchone();

$field->Owner['Iron'] += $field->ressource_amount;
$field->save();

EDIT: En realidad no sé si eso va a trabajar ... esto se parece más a lo que hago

$q = Doctrine_Query::create()
    ->select('*')
    ->from('Field')
    ->where('ressource_id = ?',1); //btw resource has one 's'

$field = $q->fetchone();

$user = $field->Owner;
$user['Iron'] += $field->ressource_amount; // I have never used a += like this, but in theory it will work.
$user->save();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top