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

  • Home
  • SEARCH
  • 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 8770839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:38:21+00:00 2026-06-13T17:38:21+00:00

I have a schema for a relational database, which I’d like to generate scaffolding

  • 0

I have a schema for a relational database, which I’d like to generate scaffolding for in my Ruby on Rails 3.2.8 project. I’ve found the documentation pretty confusing though, and my efforts so far have failed, so my question is exactly how I’d go about generating the needed scaffolding/models for the following schema:

USER
name:string
email:string
-----
has_many: posts

TAG
name:string
-----
belongs_to_and_has_many: series
belongs_to_and_has_many: posts

POST
title:string
body:text
-----
belongs_to_and_has_many: tags
belongs_to: user
belongs_to: category

SERIES
name:string
website:string
-----
belongs_to_and_has_many: tags

CATEGORY
name:string
-----
has_many: posts

Picture of schema

  • 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-13T17:38:22+00:00Added an answer on June 13, 2026 at 5:38 pm

    Here we go :

    rails g scaffold User email:string password:string
    rails g scaffold Category name:string
    rails g scaffold Post title:string body:text category:references user:references
    rails g scaffold Tag name:string
    rails g scaffold TagsPost post:references tag:references
    rails g scaffold Serie name:string website:string
    rails g scaffold TagsSerie serie:references tag:references
    

    Here I’m using references because it has the added benefit of automatically generating an index on the column for you. Although the DB generation is nice, I suggest you review the actual db/migrations files generated and add more indexes etc …

    If you don’t want indexes by default, just generate using model_name_id:integer like serie_id:integer (Note the singular form here)

    I’d also consider renaming your association tables to be singular : TagPost and TagSerie since it’s an association between a Tag and either a Serie or a Post

    Also beware, when generating automatic rails compliant foreign keys, they’ll by default be named model_name_id and not id_users as your schema mentions. All of this can be changed but it’s easier to make Rails figure out everything for you. Convention over configuration is one of the big strength of Rails.

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

Sidebar

Related Questions

I have a table which have schema like this id name 1 jack 2
Let's imagine I have a relational database in which, among other things, I want
I have the following database relational schema that purports to model an EMP supertype
I have a schema design that looks like this: Table: User Row Column Family
I have xsd schema file which I can't change. Here is an excerpt that
I have a schema like this <h1> 5/2009 <br/> Question: This is the question
I have an XML file which I'd like to query (read/write) in the same
I have to map a large enterprise database schema. As a number of legacy
This is the database schema we have. t_RoleCombinations - These are all possible combination
Which Database table Schema is more efficient and why? Users (UserID, UserName, CompamyId) Companies

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.