E
E
EVOSandru62015-04-30 03:36:26
Yii
EVOSandru6, 2015-04-30 03:36:26

Why is a relation in Yii treated as a non-existent property?

Hey!
I have 2 tables:
t_product (CODE[ int ], NAME) - derived class Product
l_order_22_product (CODE, PRODUCT_CODE[ int ], COUNT[ int ]) - LOrder22Product
class In the LOrder22Product class, the links are written:

public function relations()
  {
    return array(
      'product' => array(self::BELONGS_TO, 'Product', 'PRODUCT_CODE'),
      'orders' => array(self::BELONGS_TO, 'Orders', 'ORDER_CODE'),
    );
  }

If somewhere in the code I write:
$mod = LOrder22Product::model()->findByPk(13);
echo $mod->product->NAME;

Falls out:
The property "LOrder22Product.product" is not defined.
Although this is not a property, but a relationship, what could be the reason for the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Marinov, 2015-05-11
@felessar

Yii picks up connected models very well if foreign keys are affixed to the corresponding tables. Have you set up foreign keys?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question