arel methods in scope cause issues with non-existent tables of models with STI #8877

Closed
mrudhukar opened this Issue Jan 10, 2013 · 3 comments

Projects

None yet

2 participants

@mrudhukar

The issue arises if a model's table doesn't exist yet but the model is being loaded as part of the environment, which for example below, happens if an observer is defined on said model
Here is my setup of a basic rails app

class Program < Organization
  scope :published_programs, where(:published => true)
end

class Organization < ActiveRecord::Base
end

class ProgramObserver < ActiveRecord::Observer
  observe :program
end

config.active_record.observers = :program_observer

This is the error I get when I try to do load the environment without the tables (during rake db:migrate)
Mysql2::Error: Table 'groups_development.organizations' doesn't exist: SHOW FULL FIELDS FROM organizations

I think this happens because of the call columns_hash call in the descends_from_active_record? call in the ActiveRecord::Inheritance

@senny
Member
senny commented Feb 25, 2013

could you post the complete stack trace of your error? I suspect the origin is the scope definition. With rails 4 scopes will no longer be evaluated when loading the model file. This way we can delay the access to the database.

Can you verify if your problem persists on rails/master?

@senny
Member
senny commented Apr 9, 2013

Without further debugging information It is hard to assist. I'm closing since it's been a month since we heard from you. Please report back if this is still an issue and attach the relevant information. Also note that observers were extracted from Rails and won't be in Rails 4. They now live here: https://github.com/rails/rails-observers

Thanks for reporting 💛

@senny senny closed this Apr 9, 2013
@mrudhukar

Hey, I am sorry.. I am caught up with my work... When I get some time, I
will try to check this on rails/master, and if there is an issue I will
reopen it....

Thank you,

On Tue, Apr 9, 2013 at 7:22 PM, Yves Senn notifications@github.com wrote:

Without further debugging information It is hard to assist. I'm closing
since it's been a month since we heard from you. Please report back if this
is still an issue and attach the relevant information. Also note that
observers were extracted from Rails and won't be in Rails 4. They now live
here: https://github.com/rails/rails-observers

Thanks for reporting [image: 💛]


Reply to this email directly or view it on GitHubhttps://github.com/rails/rails/issues/8877#issuecomment-16113503
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment