Inserting into vertical tables with AR

Is there anything built into Yii2 AR or a plugin that can help with the following situation.

I have a table that holds a record and another table that inserts meta data.

Table

part_topic

 - id


 - more stuff


 ...

part_topic_item

- id


- part_topic_id_fk


- name


- value

So I’d have 1 row referring to the part_topic and multiple part_topic_item rows. These would be entered off the same form most likely.

My current solution has been to just create the part_topic and then forloop the inputs and manually create a new part_topic_item model, set the part_topic_item_id_fk with newly created part_topic’s id and save a new part_topic_item model.

Is there a better alternative?

What you have there, in the part_topic_item table looks like a EAV model which you can easily handle in yii as described at http://www.yiiframework.com/doc-2.0/guide-input-tabular-input.html

So your approach is the correct one, you just need to make use of Yii’s Model::loadMultiple and Model::validateMultiple to make your live easier.

Thanks for the link!