Skip to content

Commit

Permalink
Used ConventionsTrait::_modelKey() to create FKs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Sep 12, 2014
1 parent ab24722 commit 15cc486
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/ORM/Association.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\ORM;

use Cake\Core\ConventionsTrait;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Datasource\ResultSetDecorator;
use Cake\Event\Event;
Expand All @@ -30,6 +31,8 @@
*/
abstract class Association {

use ConventionsTrait;

/**
* Strategy name to use joins for fetching associated records
*
Expand Down
3 changes: 1 addition & 2 deletions src/ORM/Association/BelongsTo.php
Expand Up @@ -41,8 +41,7 @@ class BelongsTo extends Association {
public function foreignKey($key = null) {
if ($key === null) {
if ($this->_foreignKey === null) {
$key = Inflector::singularize($this->target()->alias());
$this->_foreignKey = Inflector::underscore($key) . '_id';
$this->_foreignKey = $this->_modelKey($this->target()->alias());
}
return $this->_foreignKey;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ORM/Association/BelongsToMany.php
Expand Up @@ -123,8 +123,7 @@ class BelongsToMany extends Association {
public function targetForeignKey($key = null) {
if ($key === null) {
if ($this->_targetForeignKey === null) {
$key = Inflector::singularize($this->target()->alias());
$this->_targetForeignKey = Inflector::underscore($key) . '_id';
$this->_targetForeignKey = $this->_modelKey($this->target()->alias());
}
return $this->_targetForeignKey;
}
Expand Down
4 changes: 1 addition & 3 deletions src/ORM/Association/ExternalAssociationTrait.php
Expand Up @@ -15,7 +15,6 @@
namespace Cake\ORM\Association;

use Cake\ORM\Association\SelectableAssociationTrait;
use Cake\Utility\Inflector;

/**
* Represents a type of association that that needs to be recovered by performing
Expand Down Expand Up @@ -55,8 +54,7 @@ public function canBeJoined(array $options = []) {
public function foreignKey($key = null) {
if ($key === null) {
if ($this->_foreignKey === null) {
$key = Inflector::singularize($this->source()->alias());
$this->_foreignKey = Inflector::underscore($key) . '_id';
$this->_foreignKey = $this->_modelKey($this->source()->alias());
}
return $this->_foreignKey;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ORM/Association/HasOne.php
Expand Up @@ -42,8 +42,7 @@ class HasOne extends Association {
public function foreignKey($key = null) {
if ($key === null) {
if ($this->_foreignKey === null) {
$key = Inflector::singularize($this->source()->alias());
$this->_foreignKey = Inflector::underscore($key) . '_id';
$this->_foreignKey = $this->_modelKey($this->source()->alias());
}
return $this->_foreignKey;
}
Expand Down

0 comments on commit 15cc486

Please sign in to comment.