I wont say I solved my problem - but I did hack around it.
If anyone has any suggestions for a cleaner way to do this - I'm open to suggestions.
I created a custom_gc_model with the following code:
function get_relation_n_n_already_used_array($field_info)
{
$select = "";
$related_field_title = $field_info->title_field_selection_table;
$use_template = strpos($related_field_title,'{') !== false;;
$field_name_hash = $this->_unique_field_name($related_field_title);
if($use_template)
{
$related_field_title = str_replace(" ", " ", $related_field_title);
$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
}
else
{
$select .= "$related_field_title as $field_name_hash";
}
$this->db->select('*, '.$select,false);
$selection_primary_key = $this->get_primary_key($field_info->selection_table);
if(empty($field_info->priority_field_relation_table))
{
if(!$use_template){
$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
}
}
else
{
$this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}");
}
$this->db->join(
$field_info->selection_table,
"{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}"
);
$results = $this->db->get($field_info->relation_table)->result();
$results_array = array();
foreach($results as $row)
{
$results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash};
}
return $results_array;
}
function get_relation_n_n_unselected_array($field_info, $selected_values)
{
$already_used=$this->get_relation_n_n_already_used_array($field_info);
$use_where_clause = !empty($field_info->where_clause);
$select = "";
$related_field_title = $field_info->title_field_selection_table;
$use_template = strpos($related_field_title,'{') !== false;
$field_name_hash = $this->_unique_field_name($related_field_title);
if($use_template)
{
$related_field_title = str_replace(" ", " ", $related_field_title);
$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
}
else
{
$select .= "$related_field_title as $field_name_hash";
}
$this->db->select('*, '.$select,false);
if($use_where_clause){
$this->db->where($field_info->where_clause);
}
$selection_primary_key = $this->get_primary_key($field_info->selection_table);
if(!$use_template)
$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
$results = $this->db->get($field_info->selection_table)->result();
$results_array = array();
foreach($results as $row)
{
if(!isset($already_used[$row->$selection_primary_key]))
$results_array[$row->$selection_primary_key] = $row->{$field_name_hash};
}
return $results_array;
}
Your thoughts ??
Cheers
Ez