Hi all.
I have a pivot table between two model. And are there any possibility to generate forms with this relations (via Gii)?
Here the SQL:
CREATE TABLE IF NOT EXISTS `tbl_em_event` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`procurer` varchar(255) NOT NULL,
`start_time` datetime NOT NULL,
`end_time` datetime NOT NULL,
`number` mediumint(9) NOT NULL,
`style_hospitality` text,
`style_setup` text,
`demand_humanresource` text,
`demand_technical` text,
`shortscenario` text,
`comment` text,
`responsible_person` varchar(255) NOT NULL,
`form_date` double NOT NULL,
`created_by` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `created_by` (`created_by`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `tbl_em_event_instrumental`
--
CREATE TABLE IF NOT EXISTS `tbl_em_event_instrumental` (
`event_id` int(11) NOT NULL AUTO_INCREMENT,
`instrumental_id` int(11) NOT NULL,
KEY `instrumental_id` (`instrumental_id`),
KEY `event_id` (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `tbl_em_instrumental`
--
CREATE TABLE IF NOT EXISTS `tbl_em_instrumental` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
The generated model:
class Event extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'tbl_em_event';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name', 'procurer', 'start_time', 'end_time', 'number', 'responsible_person', 'form_date', 'created_by'], 'required'],
[['start_time', 'end_time'], 'safe'],
[['number', 'created_by'], 'integer'],
[['style_hospitality', 'style_setup', 'demand_humanresource', 'demand_technical', 'shortscenario', 'comment'], 'string'],
[['form_date'], 'number'],
[['name', 'procurer', 'responsible_person'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'procurer' => 'Procurer',
'start_time' => 'Start Time',
'end_time' => 'End Time',
'number' => 'Number',
'style_hospitality' => 'Style Hospitality',
'style_setup' => 'Style Setup',
'demand_humanresource' => 'Demand Humanresource',
'demand_technical' => 'Demand Technical',
'shortscenario' => 'Shortscenario',
'comment' => 'Comment',
'responsible_person' => 'Responsible Person',
'form_date' => 'Form Date',
'created_by' => 'Created By',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCreatedBy()
{
return $this->hasOne(User::className(), ['id' => 'created_by']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getEventInstrumentals()
{
return $this->hasMany(Instrumental::className(), ['id' => 'event_id'])
->viaTable('tbl_em_event_instrumental', ['instrumental_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getEventLocations()
{
return $this->hasMany(Location::className(), ['id' => 'event_id'])
->viaTable('tbl_em_event_location', ['location_id' => 'id']);
}
}
And as I see in the generated forms (create, edit) I do not see any fields to add new Instrumental or Locations to the Events.
Should I implement the Instrumental and Location adding manually?
Or are there any bult-in functionality in Yii2.0?