Issue
Is there way to get current model's foreign key name in other model something like this
echo $this->Category->whatIsMyForeignKeyName();
// expected output 'category_id'
Edit: Version
strtolower($this->Category->alias).'_id'
somehow seems not in spirit of cake.
Solution
What you did with strtolower will work in almost all (or maybe all?) cases, though a slightly more thorough way would be something like:
$fkey = Inflector::singularize(Inflector::tableize($this->Category->alias)).'_id';
But the question I'd be asking is why do you want to do that? Why not just hard-code it as 'category_id'?
Answered By - joshua.paling Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.