04-30-2012, 12:26 AM
[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:
My tables:
Table "accounts":
Table "lookups":
My models:
account.php:
lookup.php:
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.
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.