Welcome Guest, Not a member yet? Register   Sign In
DataMapper: In-table Foreign Key with non-standard name
#1

[eluser]Genki1[/eluser]
Scenario: I have a one-to-many relationship with an in-table foreign key (ITFK) which has a non-standard name. I have modified the models as explained in Advanced Relationships in the section, "You want to use alternative name for a foreign key column name."

Issue: DataMapper complains that a join table cannot be found:
Quote:Error 1146: table 'accounts_lookups' does't exist". Filename: libraries/datamapper.php. Line Number: 1470.

My tables:

Table "accounts":
Code:
id
account_type_id   // ITFK, related to table "Lookups"

Table "lookups":
Code:
id
field_one

My models:

account.php:

Code:
class Account extends DataMapper {
  // related models that each record in this table can have just one of.
  var $has_one = array(
    'lookup' => array('join_self_as' => 'account_type') //ITFK is account_type_id, not lookup_id
  );
}

lookup.php:

Code:
class Lookup extends DataMapper {
  // related models that each record in this table can have many of.
  var $has_many = array(
    'account' => array('join_other_as' => 'account_type') //ITFK is account_type_id, not lookup_id
  );
}

The documentation for "You want to use alternative name for a foreign key column name" mentions only to use the attributes "join_self_as" and "join_other_as". Since I'm getting an error I guess more is needed, but the solution is not clear to me.


Messages In This Thread
DataMapper: In-table Foreign Key with non-standard name - by El Forum - 04-30-2012, 12:26 AM
DataMapper: In-table Foreign Key with non-standard name - by El Forum - 04-30-2012, 02:41 AM
DataMapper: In-table Foreign Key with non-standard name - by El Forum - 04-30-2012, 03:07 AM
DataMapper: In-table Foreign Key with non-standard name - by El Forum - 05-01-2012, 01:02 AM
DataMapper: In-table Foreign Key with non-standard name - by El Forum - 05-01-2012, 04:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB