OdooToOrder.php 2.39 KB
<?php
    
    namespace artbox\odoo\models;
    
    use Yii;
    use yii\db\ActiveRecord;
    
    /**
     * This is the model class for table "odoo_to_order".
     *
     * @property integer $order_id
     * @property integer $remote_id
     * @property Order   $order
     */
    class OdooToOrder extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function primaryKey()
        {
            return [
                'order_id',
                'remote_id',
            ];
        }
        
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'odoo_to_order';
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'order_id',
                        'remote_id',
                    ],
                    'required',
                ],
                [
                    [
                        'order_id',
                        'remote_id',
                    ],
                    'integer',
                ],
                [
                    [
                        'order_id',
                        'remote_id',
                    ],
                    'unique',
                    'targetAttribute' => [
                        'order_id',
                        'remote_id',
                    ],
                    'message'         => 'The combination of Order ID and Remote ID has already been taken.',
                ],
                [
                    [ 'order_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Order::className(),
                    'targetAttribute' => [ 'order_id' => 'id' ],
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'order_id'  => Yii::t('odoo', 'Order ID'),
                'remote_id' => Yii::t('odoo', 'Remote ID'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getOrder()
        {
            return $this->hasOne(Order::className(), [ 'id' => 'order_id' ])
                        ->inverseOf('odooToOrder');
        }
    }