Page 1 of 1

getRelatedRecordObject

PostPosted: Mon Aug 30, 2010 2:28 am
by Babs
Hello,

I think there is a problem with related record objects.
The function Dataface_RelatedRecord->_initValues() doesn't take into account that two tables could have the same column names.

For exemple, I have 2 tables table1 and table2 which have each a column named 'id'.

Code: Select all
function _initValues(){
      [...]
         $this->_absoluteColumnNames = array();
         //$cols = $this->_relationship->_schema['columns'];
         $cols = $this->_relationship->fields(true); // we will get all fields - even grafted ones.

$cols = array('table1.id', 'table2.id')

Code: Select all
         foreach ($cols as $col){
            list($table, $field) = explode('.', $col);
            $this->_values[$field] = null;
            $this->_absoluteColumnNames[$field] = $col;
         }
      }
   }


=> we get only one column name 'id'

I hope I'm clear enough

Re: getRelatedRecordObject

PostPosted: Wed Sep 01, 2010 10:48 am
by shannah
You are correct. This is a limitation of the current implementation. A relationship is set up to have unique column names so if both tables in the relationship have identical column names it will only use one of them.

Re: getRelatedRecordObject

PostPosted: Wed Sep 01, 2010 11:51 pm
by Babs
OK, so my columns should be idTable1 and idTable2...
Thank you for your answer!

Re: getRelatedRecordObject

PostPosted: Thu Sep 02, 2010 9:33 am
by shannah
Most of the time it's not a problem. It is only an issue when a relationship involved more than 1 destination table (many-to-many relationship). In these cases often the join table won't have an id of its own... its primary key will often just consist of foreign keys to the other two tables. In which case it's not a problem if they have the same names because they will also contain the same values.
Having a different name for the id column in each table is probably good practice anyways.