CakePHP HABTM:如何查找所有照片HABTM多个标签?
我有两个表,照片和标签,以及标准的 photos_tags 链接表。
我的模型显示照片 HABTM 标签,我可以通过更新链接来很好地更新两者。
我的问题是:假设我现在想要查找所有标记有“日落”和“海洋”的照片 - 我该怎么做?
我尝试按照 Nate's Bakery post,我现在可以找到带有其中一个或两个标签的所有照片,但我只想要那些带有两个标签的照片(例如“AND”查找,如果这是正确的短语)。目前添加更多标签会给我更多结果 - 随着添加更多标签,我想要更少的结果!
或者,如果没有好的 Cakey 方法,你会怎么做?多次搜索然后比较数组?虽然看起来有点浪费……
TIA。
I have two tables, photos and tags, with a standard photos_tags link table.
My models show Photos HABTM Tags, and I can update both fine with the links updating too.
My question is: say I now want to find all Photos tagged with both "Sunset" and "Ocean" - how do I go about that?
I've tried doing an inner join as per Nate's Bakery post and I can now find all photos tagged with either OR both, but I want just those with both tags (e.g. an "AND" find, if that's the correct phrase). Currently adding more tags gives me more results - I want less results as more tags are added!
Alternatively, if there isn't a nice Cakey way, how would you do it? Multiple searches and then compare the arrays? Seems kinda wasteful though...
TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样绑定条件数组
You can bind condition arrays like this