R
R
REGETT2015-05-29 11:44:35
Yii
REGETT, 2015-05-29 11:44:35

Should linking work in yii2 child class?

Why is the connection not clinging?

class Foo extends ActiveRecord{
    ....
}

class Bar extends Foo{

    public function getOption(){
        return $this->hasOne(...);
    }
}

Attempt to access:
var_dump($bar->option);
Returns:
Undefined property: app\models\Bar::$option
PS Forgot Yii2 tag
Dealing with links: www.yiiframework.com/doc-2.0/guide-db-active-recor...
PPS
I put the link in Bar and instantiate it and no link is created even though its parent is inherited from AR

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Khomenko, 2015-05-29
@iiifx

Returns:
Undefined property: app\models\Foo::$option

All right. You've set the link to Bar, not Foo.
The child gets access to all parent implementations. The parent does not receive anything from the heir.
I will add that this is not Yii2, this is the basics of OO programming. Read a few books, otherwise it will be difficult for you to work with him.

M
Mishutka2000, 2015-05-29
@Mishutka2000

The connection is formed by the attributes of the model. Most likely, in your BAR model, the ID attribute (or what do you have?) is not defined, according to which the binding is carried out.
Show the complete initialization code of the Bar model and also what you have in hasOne(...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question