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

Popular posts from this blog

css - I want to align grid in center -

Contact Form PHP Email Script -

python - SWIG function not printing output -