Answer the question
In order to leave comments, you need to log in
Creating complex shapes in Yii2 from multiple models?
Good evening.
Help a newbie please.
It is necessary to make a complex form, according to the type
- Country
- name
- 2-letter code,
then an array of objects of cities
--- city1 (properties)
--- city2 (properties)
--- city3 (properties)
the property of the city means (name, population etc.)
Thank you.
Answer the question
In order to leave comments, you need to log in
Good evening.
A couple of links to the official documentation:
First
Second
This is for starters, then see for yourself on the documentation.
slo_nik , thanks for the links.
I read it, but you know what the result is.
If possible, I will try to be specific
. I created 2
City models with attributes
'_id',
'city_code',
'city_name',
'country_id',
and
Country with attributes
'_id',
'country_code',
'country_name',
I need, for example , in the controller CountryController in actionCreate
somehow combine the whole thing to get such a record in the mongoDb database
{
"_id" : ObjectId("58c5a44f0640fd34f5407f68"),
"country_code" : "BY",
"country_name" : "Belarus",
"cities" : [
{
"_id" : ObjectId("58c5bfe70640fd34f5407f6a"),
"city_code" : "MSQ",
"city_name" : "Minsk",
"country_id" : ObjectId("58c5a44f0640fd34f5407f68")
},
{
"_id" : ObjectId("58c5bfe70640fd34f5407g75"),
"city_code" : "BQT",
"city_name" : "Brest",
"country_id" : ObjectId("58c5a44f0640fd34f5407f68")
}
]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question