alxkolm

city user model

Sep 30th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2.  
  3. use yii\db\ActiveRecord;
  4.  
  5. class City extends ActiveRecord {
  6.  
  7.     public function rules()
  8.     {
  9.         return [
  10.             ['name', 'string']
  11.         ];
  12.     }
  13. }
  14.  
  15. class User extends ActiveRecord {
  16.  
  17.     public function rules()
  18.     {
  19.         return [
  20.             ['city_id', 'exist', 'targetClass' => City::className(), 'targetAttribute' => 'id']
  21.         ];
  22.     }
  23.    
  24.     public function getCity()
  25.     {
  26.         return $this->hasOne(City::className(), ['id' => 'city_id']);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment