IceJOKER
(Admin)
1
Hi, how to save many to many data?
I have post table [id, ‘title’], category[‘id’, ‘title’] and junction table post_category[post_id, category_id]
How to save these data:
{
"title": "My new post",
"categories": "1,2,3,4"
}
OR
{
"title": "My new post",
"categories": [1, 2, 3]
}
dimis283
(Dimis283)
2
Did you look at link()?
$user = new User;
$user->name = 'Foo';
$user->save();
$market = new Market;
$market->name = 'Bar';
$market->save();
$user->link('markets', $market);
http://www.yiiframework.com/doc-2.0/yii-db-baseactiverecord.html#link()-detail