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

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

android - IBM Worklight 6.1 [Application Error] There was a network error (file:///android_asset/www/index.html) -