hasOne(Product::className(), ['id' => 'id_product']); } /** * @inheritdoc */ public function rules() { return [ [['id_order', 'id_product', 'quantity'], 'required'], [['id_order', 'id_product', 'id_tax_rate'], 'integer'], [['unit'], 'string', 'max' => 255], [['quantity'], 'number', 'min' => 0], [['description'], 'safe'] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'id_order' => 'Commande', 'id_product' => 'Product', 'quantity' => 'Quantité', 'unit' => 'Unité', 'id_tax_rate' => 'Taxe', 'description' => 'Description' ]; } /** * Retourne les options de base nécessaires à la fonction de recherche. * * @return array */ public static function defaultOptionsSearch() { return [ 'with' => ['taxRate'], 'join_with' => [], 'orderby' => '', 'attribute_id_producer' => '' ]; } public function afterFind() { if ($this->taxRate == null) { $this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate); } parent::afterFind(); } public function getTaxRate() { return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']); } }