Rails delete record fails -


i have ruby app have documents model. documents can added cart download. once cart downloaded items in cart can wiped out , cart deleted. running problem when try destroy document. i'm getting

activerecord::statementinvalid in documentscontroller#destroy tinytds::error: invalid object name 'tl.carts_documents'.: exec sp_executesql n'delete [tl].[carts_documents] [tl].[carts_documents].[document_id] = @0; select @@rowcount affectedrows', n'@0 int', @0 = 3  rails.root: c:/users/cmendla/rubymineprojects/technical_library  application trace | framework trace | full trace app/controllers/documents_controller.rb:150:in `destroy' request  parameters:  {"_method"=>"delete",  "authenticity_token"=>"t0jba. . . 3q==",  "id"=>"3"} 

.

class document < activerecord::base    belongs_to :category, :class_name => 'category', :foreign_key => 'category_id'  # belongs_to :owner, :class_name => 'owner', :foreign_key => 'owner_id'   has_and_belongs_to_many :carts, :dependent => :destroy   accepts_nested_attributes_for :carts 

.

class cart < activerecord::base    has_and_belongs_to_many :documents   has_many :items, :dependent => :destroy   accepts_nested_attributes_for :items 

.

class item < activerecord::base   belongs_to :cart end 

. activerecord::schema.define(version: 20160119182713) do

  create_table "carts", force: :cascade |t|     t.string   "user"     t.datetime "created_at", null: false     t.datetime "updated_at", null: false   end     create_table "documents", force: :cascade |t|     t.string   "document_title"     t.text     "summary"     t.integer  "owner_id"     t.integer  "category_id"     t.datetime "created_at",            null: false     t.datetime "updated_at",            null: false     t.string   "doc_file_file_name"     t.string   "doc_file_content_type"     t.integer  "doc_file_file_size"     t.datetime "doc_file_updated_at"     t.string   "owner_index"     t.string   "category_index"   end    create_table "items", force: :cascade |t|     t.integer  "document_id"     t.string   "user"     t.integer  "cart_id"     t.datetime "created_at",  null: false     t.datetime "updated_at",  null: false   end    add_index "items", ["cart_id"], name: "index_items_on_cart_id" 

.

def destroy         @document.destroy     respond_to |format|       format.html { redirect_to documents_url, notice: 'document destroyed.' }       format.json { head :no_content }     end   end 

this running on microsoft sql server database don't think constraint issue. main question if models correct allow deletion of document. don't care if wipes out associated items. once documents downloaded, cart , associated items no longer used.

has_and_belongs_to_many relationship expects join table created part of migration. in case, missing creation of 'carts_documents' in migration.

visit active record associations , active record api more info


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -