I've got so used to using Fuel's relationship table and configuration that I'd nearly forgotten how to create custom relationships in the Fuel admin.
I'm using the Ion Auth library again, and wanted to use the "multi" field type on the user-to-groups relationships.
So I looked up a similar thing I did months back, using v0.93 of Fuel. In the users_model form_fields() method I get the associated groups back from the look-up table "users_groups" by doing this:
$users_groups = array();
$CI = &get_instance();
$key = isset($values['id']) ? $values['id'] : NULL;
...
$users_groups = array_keys($CI->users_groups_model->find_all_array_assoc('group_id', array('user_id' => $key)));
then build the field like so
$fields['groups'] = array('label' => 'Groups', 'type' => 'multi', 'model' => 'groups', 'value' => $users_groups, 'mode' => 'multi');
That still works great, but it isn't very v1.0. Can't this be defined as a relationship, only without using the fuel_relationships table, but the users_groups one instead - ie as a model property? I'm sure I have done that in v1.0 install, but I can't find where.
Comments
relationships_model = a model for the lookup table,
foreign_key = the key used for the foreign model
candidate_key = the key used for current model to associate with
Code may look something similar to this:
public $has_many = array('categories' => array('model' => 'categories_model', 'module' => 'app', 'relationship_model' => 'my_relationships_model', 'foreign_key' => 'category_id', 'candidate_key' => 'my_id');
Thanks!