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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:03:23+00:00 2026-05-24T14:03:23+00:00

There are Thing s in Place s which I’m looking to find. One Thing

  • 0

There are Things in Places which I’m looking to find. One Thing could be in many different Places, and many Things can be in one Place.

class Thing < ActiveRecord::Base
  has_and_belongs_to_many :places
end

class Place < ActiveRecord::Base
  has_and_belongs_to_many :things
end

I want to record the Finds of my Users so that I know where they found what.

class Find < ActiveRecord::Base
  belongs_to :user
  belongs_to :places_thing # Is this depluralization correct?
end

class User < ActiveRecord::Base
  has_many :finds
  # Now, how can I link in the Things the user has found? Like this?
  has_many :found_things_in_places, :class_name => :places_things, :through => :finds
  has_many :things, :through => :thought_things_in_places
end

Does this seem right? is it efficient? Thanks.

  • 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-24T14:03:23+00:00Added an answer on May 24, 2026 at 2:03 pm

    I think you were on the right track, the big change I’d make is that rather than having a join table (places_things) you should make it a proper model. I decided to call this an existence.

    The data only exists in one place, so it’s properly normalized. These relationships are clear and will be easy to manage. I think it’s efficient.

    class Place < ActiveRecord::Base
      has_many :existences
      has_many :things, :through => :existences
    end
    
    class Thing < ActiveRecord::Base
      has_many :existences
      has_many :places, :through => :existences
    end
    
    class Existence < ActiveRecord::Base
      belongs_to :place
      belongs_to :thing
    end
    
    class Find < ActiveRecord::Base
      belongs_to :user
      belongs_to :existence
    end
    
    class User < ActiveRecord::Base
      has_many :finds
      has_many :existences, :through => :finds
      has_many :things, :through => :existences
    end
    

    You’ll need rails 3.1 to do the nested has many through’s like we did in User.

    BTW the correct association declaration should be: belongs_to :places_things

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

Sidebar

Related Questions

There is still a part of me which things this Zend thing is a
I can't help but thing there is a better way of coding the below
There is one thing I really love about LXML, and that the E builder.
There is one thing I never understood about references and I hope that one
Is there such a thing? I know that I can hook my function on
Are these the same thing? If so, why are there so many terms?! Also,
I have an image, on which I want to place links, which could be
I have a model Thing which can be subclassed by several types of Thing
Is there any useful hook in ASP.NET MVC (MVC4) which can let you access
There's such thing as __w64 in Visual C++ 9. I came across it while

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.