Select a posts with specific tags using Yii activeRecord -
i have typical setup models post, tag, , posttag (an associative model/table), follows:
post id, title
tag, id, name
posttag id, post_id, tag_id
can tell me how structure activerecord statement posts have multiple specific tags associated them? example, might want posts have tags named 'foo' , 'bar'. key and. it's easy posts 'foo' or 'bar'
thanks!
you can try somthing like:
post.joins(:tags).where(tags: {name: ["foo","bar"]})
Comments
Post a Comment