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 9245361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:15:01+00:00 2026-06-18T09:15:01+00:00

I have a BlogPost model with a :category attribute. I am making a new

  • 0

I have a BlogPost model with a :category attribute. I am making a new BlogPost form, and I would like for the select menu to populate itself with each category entered in previous records by the user.

Therefore, I need one query to find all BlogPosts with a User ID, and then round up a list of each category they have entered. The same category will exist in multiple records, but of course I only want to return copy of it for the select menu.

Thank you 🙂

  • 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-06-18T09:15:02+00:00Added an answer on June 18, 2026 at 9:15 am

    You can SELECT DISTINCT categories returned an INNER JOIN to the right user :

    Category
      .joins( :posts )
      .where( posts: { user_id: current_user.id } )
      .uniq
    

    This should send a query like this :

    SELECT DISTINCT categories.*
    FROM categories
      INNER JOIN posts ON posts.category_id = categories.id
    WHERE posts.user_id = [whatever]
    

    EDIT NOTE: be wary that uniq is both a method on a Relation and on an Array. Be sure to call it on the relation before it is cast to an array, or you will perform the uniq on an array of non-distinct results, which works too, but is absurd performance-wise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model, blog_posts which has a field published_at. I'd like to select
I have a few models: 'Article, Video, BlogPost, News, Commodity'. Each are in their
I am trying to add categories to my blog, I have model class like
I have a register form created by mvc3 scaffolding. e.g. <div class=editor-label> @Html.LabelFor(model =>
In the CodeIgniter User Guide, the example model had an attribute for each field
assume that i have a BlogPost model with zero-to-many embedded Comment documents. can i
I would like to mix a field into an existing model which I would
I have a model named Post (blog post) and a model named Category .
I have a simple class: class BlogPost(models.Model): title = models.CharField(max_length=150) ... timestamp = models.DateTimeField()
First I have a Display Template in Views > Blog > DisplayTemplates: @model Domain.Model.BlogPost

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.