我使用 CakePHP 一段时间后遇到了一个问题,我需要检查该模型是否与其他模型相关联。是否有任何内置功能?
示例
BLOG
-- hasMany COMMENTS
-- hasOne Profile
COMMENTS
-- belongsTo BLOG
我正在寻找一些功能,例如:
hasAssociation('blog', 'comments'); //should return true
hasAssociation('blog', 'whatever'); //should return false
hasAssociation('profile', 'blog'); //should return false
hasAssociation('blog', 'profile'); //should return true
如果没有这样的功能我怎么能自己写呢?我不合逻辑。请提出建议。
最佳答案
你可以使用函数getAssociated
$this->yourModel->getAssociated();
并返回关联的模型
关于php - 检查一个模型是否与 cakephp 中的另一个相关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18012642/