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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:29:21+00:00 2026-05-12T16:29:21+00:00

I have a model which contains many predefined rows (> 100) and also can

  • 0

I have a model which contains many predefined rows (> 100) and also can be edited by the user.
I want to distinguish between pre-defined and user-added rows.

Because the database will be edited by a third-party application, too, I want to be on the safe side and set the default value for predefined to false in the database schema, because setting it to true will lead to serious restrictions on the row (i.e. it can never be deleted)

On the other hand the install script which creates the > 100 predefined rows now has to specify predefined = true for every row, which clutters the script.

It’s not that bad, but if there’s a simple way to change the default way from Rails it would make my script look more friendly.

In other words: I want to write this:

MyModel.create(:data => "value")

but what I want to happen is this:

MyModel.create(:data => "value", :predefined = true)

Is this possible?

EDIT: This is only an examply, actually there are some more columns I have to set differently for predefined columns.

  • 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-12T16:29:21+00:00Added an answer on May 12, 2026 at 4:29 pm

    You could do it two different ways :

    In your migrations :

    t.column :boolean :string, :default => true
    

    It defines the default value to true directly in the database.
    When you change it, you have to create a new migration.

    In your model :

    def before_create
        predefined = true if predefined.nil?
    end
    

    It defines the value to “true” unless you already defined it to something else.
    You can change the value just by changing it in the model.

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

Sidebar

Ask A Question

Stats

  • Questions 189k
  • Answers 189k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Taking of .CustomSqlType("int") solves the problem May 12, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer One of the features of the query planner introduced in… May 12, 2026 at 5:49 pm
  • Editorial Team
    Editorial Team added an answer Found the problem. The window constructor happens BEFORE the YesNoComboBox_Loaded.… May 12, 2026 at 5:49 pm

Related Questions

I'm working on a Web service in Django, and I need to model a
Suppose I have a Book model, which contains many Page models. The routing for
I have an ASP.Net MVC application with a model which is several layers deep
I have a Character model and a Link model. The Link model represents a
I have a form which contains a whole heap of data entry fields that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.