gpt4 book ai didi

php - 检查一个模型是否与 cakephp 中的另一个相关联?

转载 作者:搜寻专家 更新时间:2023-10-31 20:43:06 25 4
gpt4 key购买 nike

我使用 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();

并返回关联的模型

http://book.cakephp.org/2.0/en/models/additional-methods-and-properties.html#model-getassociated-string-type-null

关于php - 检查一个模型是否与 cakephp 中的另一个相关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18012642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com