petehamilton / citier

CITIER (Class Inheritance & Table Inheritance Embeddings for Rails) is a solution for simple Multiple Class Inheritance in Rails.
88 stars 24 forks source link

update_all raises ActiveRecord::StatementInvalid #64

Open robotex82 opened 11 years ago

robotex82 commented 11 years ago

Using:

When I call update_all on a acts_as_citier child class with additional attributes

I get:

ActiveRecord::StatementInvalid: SQLite3::SQLException: cannot modify view_ecm_references_item_pictures because it is a view: 
UPDATE "view_ecm_references_item_pictures" 
SET "updated_at" = '2012-12-11 13:28:02.581609' 
WHERE "view_ecm_references_item_pictures"."id" IN (SELECT "view_ecm_references_item_pictures"."id" FROM "view_ecm_references_item_pictures"  WHERE "view_ecm_references_item_pictures"."type" IN ('Ecm::References::Item::Picture') ORDER BY position ASC)

The models:

class Ecm::Assets::Asset < ActiveRecord::Base
  # acts as citier
  acts_as_citier :table_name => 'ecm_assets_assets'

  # associations
  belongs_to :assetable, :polymorphic => true

  # attributes
  attr_accessible :assetable_id,
                  :assetable_type,
                  :attachment,
                  :type

  def url(*args)
    attachment.url(*args) if attachment.present?
  end
end

module Ecm::References
  class Item::Picture < ::Ecm::Assets::Asset
    # database settings
    self.primary_key = 'id'

    # attachments
    has_attached_file :attachment, :styles => { :default_thumbnail => "64x64>", :default => "64x64>" }

    # mti
    acts_as_citier :table_name => 'ecm_references_item_pictures'

    # positioning
    default_scope :order => 'position ASC'
    acts_as_list :scope => :assetable

    # validations
    validates_attachment_presence :attachment
  end
end

I had to set the primary key on the picture model, otherwise I got errors.This seems strange to me, too.

The problem is that the update_all uses the view when trying to update. AFAIK this is not possible in sql. Any cluse, how to solve this? Any other people, with the same problem?

Thanks in advance!