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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:25:38+00:00 2026-06-11T21:25:38+00:00

I am designing a database schema for my project, where I seem to have

  • 0

I am designing a database schema for my project, where I seem to have been stuck by a strange vision-block (in the sense that, I have never had this issue before since its virtually too easy to resolve, except in this particular case – for me)

I have an entity homes, that can have various facilities.
So, I have declared a model: FacilitySet that looks like:

id, home_id, parking, electricity  

As you can see, each row of facility_sets table corresponds to a Home.

But, in my opinion, it would make a whole lot more sense to me, if I could say: a home has_many facilities, rather than a home has_one facility_set. This, also, provides an advantage that I can simply say: @home.facilities, rather than @home.facility_set

The real problem is that I can not understand how to structure the facilities table in the database, so that I can simply declare:

class Home << ActiveRecord::Base
  has_many :facilities
  ..
end

and access facilities like: @home.facilities

I am, currently, doing:

class Home << ActiveRecord::Base
  has_one :facility_set
  ..
end

and access facilities like: @home.facility_set, which really makes me feel I am doing something horribly wrong!! :~)

Its early morning here, and I would really really appreciate any ray-of-ho(m)e for me.

Regards

  • 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-11T21:25:39+00:00Added an answer on June 11, 2026 at 9:25 pm
    class InitSchema < ActiveRecord::Migration
      def change
        create_table :homes do |t|
          t.integer :id, null: false
          # ...
        end
    
        create_table :facilities do |t|
          t.integer :id, null: false
          t.integer :home_id, null: false
          t.string :name, null: false
          t.string :value, null: false
        end
      end
    end
    
    class Home < ActiveRecord::Base
      has_many :facilities
    end
    
    class Facility < ActiveRecord::Base
      belongs_to :home
    end
    

    Now use the facilities name and values field to store things like parking, electricity, etc. You may want to create a FacilityType class that has_many Facilities, and keep parking, electricity, etc., in there.

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

Sidebar

Related Questions

I am designing a database for a project. I have a table that has
I have never designed a database/data-model/schema from scratch, especially for a web-application. In some
I'm designing a database schema using PostgreSQL. I have some doubts about which design
I have a database that increases every month. The schema remains the same, so
I am designing a relational database schema that may be ported to multiple database
Assuming you have a business that rents movie and you were designing a schema
I want to run an alter database query on the Schema I am designing
I am designing database tables for a master-detail scenario. The specific requirement is that
We are designing database schema for a new system based on Oracle 11gR1. We
I am presently designing a database schema for use in a Rails 3.1 application.

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.