Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6649075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:43:53+00:00 2026-05-26T00:43:53+00:00

I setup a HABTM relationship between my post model, genre model, and genres_posts model.

  • 0

I setup a HABTM relationship between my post model, genre model, and genres_posts model. My genre model has a name:string attribute which consists of names like ‘thriller’ ‘western’ ‘horror’ ‘action’ comedy’ etc, when a user creates a post they can add 1 or more genres to the post.

I need to be able to list all of a user’s posts by the specific genre, so they can easily switch back and forth between all their posts with genre ‘western’ and all the posts with genre ‘action’.

Post.last.genres gives me the post’s genres, but how would I do it for an array of a user’s posts such as @user.posts ?? and then specify the specific genre name?

Is this the smartest way to do this type of thing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:43:53+00:00Added an answer on May 26, 2026 at 12:43 am

    In addition to ctcherry’s answer, this is also possible:

    @user.posts.joins(:genres).where(:genres => {:name => 'western'})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup this HABTM relationship in the past and it has worked before....Now
SETUP : I have this app which has 4 activities in a linear path,
I have a join model in a HABTM relationship with a through association (details
Setup: Tab Bar App First View is a ScrollView which has an ImageView as
Setup: IIS7 serving ASP classic VB script code which generates a dynamic VSC page/file
I have bands , genres and bands_genres database tables with a HABTM relationship I
I'm having trouble with my HABTM relationship in CakePHP. I have two models like
Setup: I was trying to understand the difference between identifying and non-identifying relationships when
Setup: I have scaffolded a controller using MvcScaffolding. For a property, Model.IdCurrencyFrom, the scaffolding
I have the following relationships set up: A HABTM B B belongsTo C C

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.