Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Frozennode/Administrator/Config/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public function setModelRelationship(&$model, Field $field)
//iterate over the items
foreach ($relatedItems as $item)
{
$keyName = $item->getKeyName();
// Modified. If this is set to 'keyName', it will not get foriegn key correctly
$keyName = $field->getOption('column');
// $keyName = $item->getKeyName();

//if this is a mutliple-value type (i.e. HasMany, BelongsToMany), make sure this is an array
if ($multipleValues)
Expand Down Expand Up @@ -544,7 +546,7 @@ public function runQueryFilter(\Illuminate\Database\Query\Builder &$query)
$filter($query);
}
}

/**
* Fetches the data model for a config given a post input array
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public function build()
$relatedModel = $relationship->getRelated();

$options['table'] = $relatedModel->getTable();
$options['column'] = $relatedModel->getKeyName();

// Assign foreign key value to column, instead of primary key
$options['column'] = $relatedModel->getOtherKey();
$options['foreign_key'] = $relationship->getForeignKey();

$this->suppliedOptions = $options;
Expand Down Expand Up @@ -71,4 +73,4 @@ public function filterQuery(QueryBuilder &$query, &$selects = null)
$query->where($this->getOption('foreign_key'), '=', $this->getOption('value'));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ public function loadRelationshipOptions(&$options)
// if no related items exist, add default item, if set in options
if (count($items) == 0 && array_key_exists('value', $options))
{
$items = $relatedModel->where($relatedModel->getKeyName(), '=', $options['value'])->get();
$items = $relatedModel->where($relationship->getOtherKey(), '=', $options['value'])->get();
}
}

//map the options to the options property where array('id': [key], 'text': [nameField])
$nameField = $this->validator->arrayGet($options, 'name_field', $this->defaults['name_field']);
$keyField = $relatedModel->getKeyName();

//fixed bug in model config when filtering by foreign key (belongsTo)
$keyField = $relationship->getOtherKey();
$options['options'] = $this->mapRelationshipOptions($items, $nameField, $keyField);
}

Expand Down Expand Up @@ -203,4 +205,4 @@ public function getDefaults()

return array_merge($defaults, $this->relationshipDefaults);
}
}
}