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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:32:20+00:00 2026-06-05T20:32:20+00:00

I have a main model called ‘Notes’ which has the following: attr_accessible :name, :label_tokens

  • 0

I have a main model called ‘Notes’ which has the following:

attr_accessible :name, :label_tokens
has_many :labelships
has_many :labels, :through => :labelships
attr_reader :label_tokens

So basically the Note_id & Label_id are kept in the Labelships table.

What i would like to do is create a list of distinct Labels and create a link on each value to the respective Note.

Example: Note ‘mynote’ has a label of ‘git’ associated through the labelship table, i would like Git to appear on a list of other labels, and then when i click on git, i get a list of Notes that have the label ‘git’ on them.

  • 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-05T20:32:22+00:00Added an answer on June 5, 2026 at 8:32 pm

    Assuming you have the following models:

    class Note
      has_many :labelships
      has_many :labels, :through => :labelships
    end
    
    class Labelships
      belongs_to :note
      belongs_to :label
    end
    
    class Label
      has_many :labelships
      has_many :notes, :through => :labelships
    end
    

    Now given a label, you can get its notes as follows:

    label.notes
    

    To exclude the note in hand:

    label.notes.where("id != ?", note.id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a google database called Main . class Main(db.Model): name = db.StringProperty() phone
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
i have main activity in which i have Four menus. and i have one
I have a main C++ app built in Visual Studio 2005, called A.exe. It
I have a backbone view - which when called presents a form $('#add-offer').click(function() {
I'm using the MVC model (I think thats what its called) and I have
I have a Model which contains an Address and Person twice, once for the
I have a model code on which kcachegrind/callgrind reports strange results. It is kind
I have a class library which is called through COM from a Third Party
I have a model called User . I have pluralize_table_names set to false so

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.