has_many_polymorphs icon indicating copy to clipboard operation
has_many_polymorphs copied to clipboard

ActionView::TemplateError: Mysql::Error in production environment

Open ian opened this issue 16 years ago • 1 comments

We're getting an interesting situation where a specific series of relationships produces an unknown column error in production only.

Consider the following: class User < ActiveRecord::Base has_many_polymorphs :accessible_products, :through => :accessibles, :as => :contact, :foreign_key => 'contact_id', :foreign_type_key => 'contact_type', :polymorphic_key => 'owner_id', :polymorphic_type_key => 'owner_type', :from => [:"product/one",:"product/two"] end

                 class Product < ActiveRecord::Base
                 has_many_polymorphs :accessors, :through => :accessibles, :as => :owner, 
                  :foreign_key => 'owner_id', :foreign_type_key => 'owner_type',
                  :polymorphic_key => 'contact_id', :polymorphic_type_key => 'contact_type',
                  :from => [:emails, :users]
                  end

                  class Accessible < ActiveRecord::Base
                  acts_as_double_polymorphic_join :owners =>[:"product/one",:"product/two"],
                              :contacts => [:users, :emails]
                  end

This cyclical relationship should be handled by the acts_as_double_polymorphic_join but it's erroring in production, possibly due preloading of models and caching them, not sure.

The error we receive in production is ActionView::TemplateError: Mysql::Error: Unknown column 'accessibles.accessible_product_id'

The foreign and polymorphic keys are clearly defined, not sure why this is happening and only in production.

ian avatar Jul 30 '09 19:07 ian

best bet is to make a failing test and fix it yourself; this project is in patch-accepting-mode only :-/

ghost avatar Aug 05 '09 21:08 ghost