Browse files

Primary key containing singular table name

  • Loading branch information...
1 parent 3419027 commit 63f25bd9089c9e8b6ba6e6cae78518100d2e1136 @vrana committed Sep 10, 2011
Showing with 9 additions and 5 deletions.
  1. +9 −5 NotORM/Structure.php
View
14 NotORM/Structure.php
@@ -67,7 +67,7 @@ function __construct($primary = 'id', $foreign = '%s_id', $table = '%s', $prefix
}
function getPrimary($table) {
- return sprintf($this->primary, $table);
+ return sprintf($this->primary, $this->getColumnFromTable($table));
}
function getReferencingColumn($name, $table) {
@@ -79,10 +79,7 @@ function getReferencingTable($name, $table) {
}
function getReferencedColumn($name, $table) {
- if ($this->table != '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '$)', $name, $match)) {
- $name = $match[1];
- }
- return sprintf($this->foreign, $name, substr($table, strlen($this->prefix)));
+ return sprintf($this->foreign, $this->getColumnFromTable($name), substr($table, strlen($this->prefix)));
}
function getReferencedTable($name, $table) {
@@ -93,6 +90,13 @@ function getSequence($table) {
return null;
}
+ protected function getColumnFromTable($name) {
+ if ($this->table != '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '$)', $name, $match)) {
+ return $match[1];
+ }
+ return $name;
+ }
+
}

0 comments on commit 63f25bd

Please sign in to comment.