getRelatedRecordObject

A place to discuss development of the Xataface core.

getRelatedRecordObject

Postby Babs » Mon Aug 30, 2010 2:28 am

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
Babs
 
Posts: 11
Joined: Wed Oct 14, 2009 4:13 am

Re: getRelatedRecordObject

Postby shannah » Wed Sep 01, 2010 10:48 am

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.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: getRelatedRecordObject

Postby Babs » Wed Sep 01, 2010 11:51 pm

OK, so my columns should be idTable1 and idTable2...
Thank you for your answer!
Babs
 
Posts: 11
Joined: Wed Oct 14, 2009 4:13 am

Re: getRelatedRecordObject

Postby shannah » Thu Sep 02, 2010 9:33 am

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.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Developers

Who is online

Users browsing this forum: No registered users and 15 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved