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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:28:22+00:00 2026-05-12T21:28:22+00:00

If my models look like this: (app/models/letter.rb) class Letter < ActiveRecord::Base def cyrilic_equivilent #

  • 0

If my models look like this:

(app/models/letter.rb)
class Letter < ActiveRecord::Base
  def cyrilic_equivilent
    # return somethign similar
  end
end

class A < Letter
end

class B < Letter
end

Can my migrations also follow this pattern:

class CreateLetter < ActiveRecord::Migration
  def self.up
    create_table :letters do |t|
      t.timestamps
    end
  end
end

class CreateA < CreateLetter
end

class CreateB < CreateLetter
end
  • 1 1 Answer
  • 1 View
  • 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-12T21:28:22+00:00Added an answer on May 12, 2026 at 9:28 pm

    What you’re trying to do won’t work at all.

    When a migration is run, Rails runs the up class method. Having a new migration inherit another migration’s up method will try to create the same table twice. This will cause the migration to fail.

    Not that it matters any way. Due to the way that migrations work Rails will only run the class that shares its name with the file that contains it.

    It looks like you’re trying to do one of two similar things here.

    1. The models suggest Single Table Inheritance. STI requires a string column named type and all subclasses will use the table of the parent model, in this case letters. You only need to define one table, and Rails takes care of all the type column mysteries when declare one model to be a subclass of another.

    2. You’re trying to define multiple similar tables and then tweak the differences. This can be done with loops and conditions in a single migration. However you will need to need to define the table_name in any of the models that are inheriting from others to disable the implied Single Table Inheritance. Your migration loop would like something like this:

      class CreateLetter < ActiveRecord::Migration
        def self.up
          [:letters, :a, :b].each do |table_name|
            create_table table_name do |t|
            ...
            t.timestamps
      
               if table_name == :a
                 # columns only in table a
               end
      
               if table_name == :b
                 # columns only in table b
               end        
             end
           end
      end
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
I've got a set of models that look like this: class Page(models.Model): title =
I have methods in all of my models that look like this: def formatted_start_date
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I've got a couple django models that look like this: from django.contrib.sites.models import Site
In Django models/forms the choices for a combobox often look like this: food_choices =
This is what my data model classes look like: public class Employee { public
I have the following structure: class FeatureType(models.Model): type = models.CharField(max_length=20) def __unicode__(self): return self.type
I have two simple models in my Django app. Here's what they look like:
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,

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.