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