From 15cc4862441a3a356506349e08ddc505fced8b08 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 11 Sep 2014 11:18:33 +0200 Subject: [PATCH] Used ConventionsTrait::_modelKey() to create FKs --- src/ORM/Association.php | 3 +++ src/ORM/Association/BelongsTo.php | 3 +-- src/ORM/Association/BelongsToMany.php | 3 +-- src/ORM/Association/ExternalAssociationTrait.php | 4 +--- src/ORM/Association/HasOne.php | 3 +-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ORM/Association.php b/src/ORM/Association.php index 4728b107e1b..0aa73267804 100644 --- a/src/ORM/Association.php +++ b/src/ORM/Association.php @@ -14,6 +14,7 @@ */ namespace Cake\ORM; +use Cake\Core\ConventionsTrait; use Cake\Database\Expression\IdentifierExpression; use Cake\Datasource\ResultSetDecorator; use Cake\Event\Event; @@ -30,6 +31,8 @@ */ abstract class Association { + use ConventionsTrait; + /** * Strategy name to use joins for fetching associated records * diff --git a/src/ORM/Association/BelongsTo.php b/src/ORM/Association/BelongsTo.php index 9078d189df6..557c0a127c9 100644 --- a/src/ORM/Association/BelongsTo.php +++ b/src/ORM/Association/BelongsTo.php @@ -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; } diff --git a/src/ORM/Association/BelongsToMany.php b/src/ORM/Association/BelongsToMany.php index 7c826b89e16..81493ab2f7e 100644 --- a/src/ORM/Association/BelongsToMany.php +++ b/src/ORM/Association/BelongsToMany.php @@ -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; } diff --git a/src/ORM/Association/ExternalAssociationTrait.php b/src/ORM/Association/ExternalAssociationTrait.php index b1e97bd63ff..362a353efe0 100644 --- a/src/ORM/Association/ExternalAssociationTrait.php +++ b/src/ORM/Association/ExternalAssociationTrait.php @@ -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 @@ -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; } diff --git a/src/ORM/Association/HasOne.php b/src/ORM/Association/HasOne.php index 74d5966ee98..1c43d27d56c 100644 --- a/src/ORM/Association/HasOne.php +++ b/src/ORM/Association/HasOne.php @@ -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; }