public function create_many($key, $data_array, $parent_name) { // $data_array is how it comes from the json encoded form data: // ['name':'something_relation[]', 'value':[0:relationid, 1:relationid]] // Model of relation is inferred by name. $return_array_models = []; $parent_name_plural = \Fuel\Core\Inflector::pluralize($parent_name); $model_name = 'Model_' . ucwords(rtrim(str_replace($parent_name_plural . '_', '', $key), 's[]')); // Won't be an array if there are no options. if (is_array($data_array)) { foreach ($data_array as $data) { $model = new $model_name(); $model->find($data); $return_array_models[] = $model; } } }