Commit 2d5412da by Junaid Rahman pv

created models for those 3 tables modified migrations for business and location(state,district)

parent 39f593c1
......@@ -25,7 +25,6 @@ class m160831_092919_business extends Migration
'contact_no' => $this->string(150),
'fax' => $this->string(512),
'email' => $this->string(1024)->notNull(),
'website' => $this->string(1024),
'description' => $this->text(),
'logo_base_url' => $this->string(1024),
'logo_path' => $this->string(1024),
......@@ -36,8 +35,8 @@ class m160831_092919_business extends Migration
'updated_at' => $this->integer(11),
], $tableOptions);
$this->createIndex('idx-business-domain_name', '{{%business}}', 'domain_name');
$this->createIndex('idx-business-email', '{{%business}}', 'email');
$this->createIndex('idx_business_domain_name', '{{%business}}', 'domain_name');
$this->createIndex('idx_business_email', '{{%business}}', 'email');
$this->addForeignKey('fk_category_id', '{{%business}}', 'category_id', '{{%category}}', 'id', 'RESTRICT', 'RESTRICT');
$this->addForeignKey('fk_district_id', '{{%business}}', 'district_id', '{{%district}}', 'id', 'RESTRICT', 'RESTRICT');
......@@ -49,8 +48,8 @@ class m160831_092919_business extends Migration
$this->dropForeignKey('fk_district_id', '{{%business}}');
$this->dropForeignKey('fk_category_id', '{{%business}}');
$this->dropIndex('idx-business-email', '{{%business}}');
$this->dropIndex('idx-business-domain_name', '{{%business}}');
$this->dropIndex('idx_business_email', '{{%business}}');
$this->dropIndex('idx_business_domain_name', '{{%business}}');
$this->dropTable('{{%business}}');
}
......
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%business}}".
*
* @property integer $id
* @property integer $category_id
* @property integer $district_id
* @property string $domain_name
* @property string $name
* @property string $slug
* @property string $address
* @property string $landmark
* @property string $mobile_no
* @property string $toll_free_no
* @property string $contact_no
* @property string $fax
* @property string $email
* @property string $description
* @property string $logo_base_url
* @property string $logo_path
* @property string $latitude
* @property string $logitude
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*
* @property Category $category
* @property District $district
*/
class Business extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%business}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['category_id', 'district_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['domain_name', 'name', 'address', 'mobile_no', 'email'], 'required'],
[['description'], 'string'],
[['domain_name'], 'string', 'max' => 255],
[['name', 'mobile_no', 'toll_free_no', 'fax'], 'string', 'max' => 512],
[['slug', 'address', 'email', 'logo_base_url', 'logo_path'], 'string', 'max' => 1024],
[['landmark'], 'string', 'max' => 500],
[['contact_no'], 'string', 'max' => 150],
[['latitude', 'logitude'], 'string', 'max' => 30],
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']],
[['district_id'], 'exist', 'skipOnError' => true, 'targetClass' => District::className(), 'targetAttribute' => ['district_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('common', 'ID'),
'category_id' => Yii::t('common', 'Category ID'),
'district_id' => Yii::t('common', 'District ID'),
'domain_name' => Yii::t('common', 'Domain Name'),
'name' => Yii::t('common', 'Name'),
'slug' => Yii::t('common', 'Slug'),
'address' => Yii::t('common', 'Address'),
'landmark' => Yii::t('common', 'Landmark'),
'mobile_no' => Yii::t('common', 'Mobile No'),
'toll_free_no' => Yii::t('common', 'Toll Free No'),
'contact_no' => Yii::t('common', 'Contact No'),
'fax' => Yii::t('common', 'Fax'),
'email' => Yii::t('common', 'Email'),
'description' => Yii::t('common', 'Description'),
'logo_base_url' => Yii::t('common', 'Logo Base Url'),
'logo_path' => Yii::t('common', 'Logo Path'),
'latitude' => Yii::t('common', 'Latitude'),
'logitude' => Yii::t('common', 'Logitude'),
'status' => Yii::t('common', 'Status'),
'created_at' => Yii::t('common', 'Created At'),
'updated_at' => Yii::t('common', 'Updated At'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCategory()
{
return $this->hasOne(Category::className(), ['id' => 'category_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getDistrict()
{
return $this->hasOne(District::className(), ['id' => 'district_id']);
}
/**
* @inheritdoc
* @return \common\models\query\BusinessQuery the active query used by this AR class.
*/
public static function find()
{
return new \common\models\query\BusinessQuery(get_called_class());
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%district}}".
*
* @property integer $id
* @property integer $state_id
* @property string $name
* @property string $slug
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*
* @property Business[] $businesses
* @property State $state
*/
class District extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%district}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['state_id', 'name'], 'required'],
[['state_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['name', 'slug'], 'string', 'max' => 1024],
[['state_id'], 'exist', 'skipOnError' => true, 'targetClass' => State::className(), 'targetAttribute' => ['state_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('common', 'ID'),
'state_id' => Yii::t('common', 'State ID'),
'name' => Yii::t('common', 'Name'),
'slug' => Yii::t('common', 'Slug'),
'status' => Yii::t('common', 'Status'),
'created_at' => Yii::t('common', 'Created At'),
'updated_at' => Yii::t('common', 'Updated At'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBusinesses()
{
return $this->hasMany(Business::className(), ['district_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getState()
{
return $this->hasOne(State::className(), ['id' => 'state_id']);
}
/**
* @inheritdoc
* @return \common\models\query\DistrictQuery the active query used by this AR class.
*/
public static function find()
{
return new \common\models\query\DistrictQuery(get_called_class());
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "{{%state}}".
*
* @property integer $id
* @property string $name
* @property string $slug
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*
* @property District[] $districts
*/
class State extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%state}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'required'],
[['status', 'created_at', 'updated_at'], 'integer'],
[['name', 'slug'], 'string', 'max' => 1024],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('common', 'ID'),
'name' => Yii::t('common', 'Name'),
'slug' => Yii::t('common', 'Slug'),
'status' => Yii::t('common', 'Status'),
'created_at' => Yii::t('common', 'Created At'),
'updated_at' => Yii::t('common', 'Updated At'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getDistricts()
{
return $this->hasMany(District::className(), ['state_id' => 'id']);
}
/**
* @inheritdoc
* @return \common\models\query\StateQuery the active query used by this AR class.
*/
public static function find()
{
return new \common\models\query\StateQuery(get_called_class());
}
}
<?php
namespace common\models\query;
/**
* This is the ActiveQuery class for [[\common\models\Business]].
*
* @see \common\models\Business
*/
class BusinessQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/
/**
* @inheritdoc
* @return \common\models\Business[]|array
*/
public function all($db = null)
{
return parent::all($db);
}
/**
* @inheritdoc
* @return \common\models\Business|array|null
*/
public function one($db = null)
{
return parent::one($db);
}
}
<?php
namespace common\models\query;
/**
* This is the ActiveQuery class for [[\common\models\District]].
*
* @see \common\models\District
*/
class DistrictQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/
/**
* @inheritdoc
* @return \common\models\District[]|array
*/
public function all($db = null)
{
return parent::all($db);
}
/**
* @inheritdoc
* @return \common\models\District|array|null
*/
public function one($db = null)
{
return parent::one($db);
}
}
<?php
namespace common\models\query;
/**
* This is the ActiveQuery class for [[\common\models\State]].
*
* @see \common\models\State
*/
class StateQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/
/**
* @inheritdoc
* @return \common\models\State[]|array
*/
public function all($db = null)
{
return parent::all($db);
}
/**
* @inheritdoc
* @return \common\models\State|array|null
*/
public function one($db = null)
{
return parent::one($db);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment