T
T
tincap2015-12-04 12:40:37
Yii
tincap, 2015-12-04 12:40:37

How to select an ActiveRecord object if the class has its own arguments in Yii2?

There is a class

/**
 * В таблице есть только одно поле - id
 * @property integer $id
 */
class Spider extends ActiveRecord
{
    private $name; // это дополнительный аргумент, которого нет в таблице

    public function __construct($name = null)
    {
        $this->name = $name;
    }
}

If somewhere now I want to delete a column, then nothing will come of it, since this is not an ActiveRecord object
// Не удалится, так как $spider не является объектом ActiveRecord
// Там есть добавленный аргумент $name;
$spider->delete();

How can I extract an ActiveRecord object from $spider?
PS
If you do print_r($spider), it will come out
(
$name -> string 'name',
private ActiveRecord -> Spider Object
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pavlenko, 2015-12-04
@Akdmeh

How is it not? Quite is, if you correctly solved the issue with namespace.
The only question is that delete only acts on existing records in the database, that is, in fact, it executes the DELETE FROM `table` WHERE `id`=:id query.
But since this is isNewRecord, there is nothing to delete there.
You need to explain the task in more detail - what do you store in this table and object and what are you going to delete?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question