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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:44:02+00:00 2026-05-28T19:44:02+00:00

I have the models shown below. I need to store some details that are

  • 0

I have the models shown below. I need to store some details that are specific a person and a house (first_viewed:date, opening offer:decimal, etc). I feel like these should belong to the PersonHouse model but I’m not certain enough. Any suggestions?

class Person < ActiveRecord::Base
  has_many :houses, through: :person_houses
  has_one :favorite_house, through: :person_houses     
end

class PersonHouse < ActiveRecord::Base
  belongs_to :house
  belongs_to :person
end

class House < ActiveRecord::Base
  has_many :house_people
  has_many :people, through: :person_houses
end

I could do something like this to get all the details but perhaps there is a more effient way.

@house = House.find(1)
@house.house_people.each do |hp|
  puts hp.person.name
  puts hp.first_viewed
  puts @house.address
end
  • 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-28T19:44:03+00:00Added an answer on May 28, 2026 at 7:44 pm

    I think your assumption is correct. If the data is relevant to the relationship between a person and a house, then yes it belongs on this model. The only recommendation I would make is to rename this model to a name that better describes what the relationship is. It doesn’t have to be the concatenation of the two models it joins. I don’t know exactly what the model is going to be ultimately used for, but SelectedHouse, HouseProspect or something along those lines might work.

    You can also delegate properties to the house or person models:

    class PersonHouse < AR::Base
      belongs_to :person
      belongs_to :house
    
      delegate :address, :to => :house, :prefix => true
      delegate :name, :to => :person, :prefix => true
    end
    
    person_house.address
    person_house.person_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added some constants to a model say MyModel.rb as shown below. MY_CONST
I have a model class that uses a custom validator as shown in following
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have that situation: I have models Item, Region and Country. class Item(models.Model): name
I need to hide/show parts of a table that is dynamically built, as shown
I have a backbone.js model similar to the one shown below. Filters = Backbone.Model.extend({
I have this delegate method below that is setting a few fields in my
I need help in writing a query, below i have written classes with needful
I have a two middleman model setup as shown below: User has_many :comments has_many
I have a model class defined as below: class Vehicle(models.Model): stock_number = models.CharField(max_length=6) vin

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.