M
M
Messi2017-09-05 12:20:05
Yii
Messi, 2017-09-05 12:20:05

How to get access to the entity from the form model?

There is a Car(Active Record) class and there is a Bike(Active Record) class.
The Car class has a link to Bike hasmany.
Created a form (extends Model) to add new records to Car;
I pass the Car model to the form class and save it via save.
The question is, in the Car form class, I need to access to save data to Bike.
How can this be done?*

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
davidnum95, 2017-09-05
@davidnum95

$bikes = $car->bikes;
foreach($bikes as $bike) {
  ...
}

M
Maxim Fedorov, 2017-09-05
@qonand

The question is, in the Car form class, I need to access to save data to Bike.

Create a Bike model object, write data to it, link to the Car object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question