vrana/notorm — Issue #37: Table Prefix, problem with left join convention structure.
Author: wendynovianto
Created: 2011-12-27 22:46:40+00:00
State: open

Hi,

There seems to be a problem with left joining, when using the convention structure. The prefix was not removed from the column name, which suppose to be a must.

Take a look this sample tables below:
- ```user : id, name, email```
- ```question : id, user_id, text, html```
- ```answer : id, user_id, question_id, text, html```

If I do this call, then it will return the left join with foreign column being referenced together with table prefix:
```$db->question()->where('answer:user_id = ?', 1);```

I fix this with:

protected function getColumnFromTable($name) {
if ($this->table != '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '$)', $name, $match)) {
return $match[1];
}
return substr($name, strlen($this->prefix)); // FIX: Remove Unnecessary Prefix
}

I haven't tested further, but I assume it might trigger abnormal behavior. Would you mind taking a look into this?

Thanks.
Wendy