Git Product home page Git Product logo

Comments (3)

BattleBrisket avatar BattleBrisket commented on September 27, 2024

You might be able to avoid the error you're seeing by creating dummy local models within the migration, matching the old and new model names.

class CreateTaggedObjects << ActiveRecord::Migration

  class TaggedObject << ActiveRecord::Base; end
  class TaggedObjectChild << ActiveRecord::Base; end

  def change
    create_table :tagged_objects do |t|
      # usual stuff here
    end
  end

end

It's worth mentioning that this is an order-of-operations issue: you are creating models for tables which don't exist yet. This is not isolated to the acts_as_relation gem, and can creep up with other complex Rails configurations. Even renaming a table can cause the same problem.

Even if the structure is still in flux, you should at least generate a migration that creates the table. You just need a placeholder, Rails shouldn't complain after that.

To avoid that landmine when I am laying out my models, I generally follow a 2-step dance:

  1. Run rails g model to give me a model and accompanying migration
  2. Run rails g migration to make any modifications to the table created in Step 1.

This only works if your Rails generator configuration is set up to create migrations along with models, so double check for setting changes to config.generators in config/application.rb.

from acts_as_relation.

hzamani avatar hzamani commented on September 27, 2024

Thanks to @BattleBrisket

from acts_as_relation.

BattleBrisket avatar BattleBrisket commented on September 27, 2024

Happy to help @hzamani !

from acts_as_relation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.