Skip to content
Permalink
Browse files

Used ConventionsTrait::_modelKey() to create FKs

  • Loading branch information...
robertpustulka committed Sep 11, 2014
1 parent ab24722 commit 15cc4862441a3a356506349e08ddc505fced8b08
@@ -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
*
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}

0 comments on commit 15cc486

Please sign in to comment.
You can’t perform that action at this time.