protected function getInstanceForModel($tag)
{
$mappings = $this->fetchMappingsForModelField($tag);
$fields = $this->fetchModelFields($tag['key'], $tag['type'], $mappings);
// if the count doesn't add up
// then create more model fields in DB
if (count($fields) != count($mappings)) {
$this->createMissingModelFields($tag, $fields, $mappings);
$fields = $this->fetchModelFields($tag['key'], $tag['type'], $mappings);
}
// sync over model values into the json values
$model = $fields[0]->model;
foreach ($fields as $field) {
$field->syncValuesWithModelValues($model);
}
return $fields;
}