Google translate.
Good afternoon, I do not know if the Bug rubyfb Rails or 3.0.10, or me doing some shit.
I refer to when I foreign_key CADUPLOAD table, the error message appears
Rubyfb::FireRubyException: Error executing SQL statement.
violation of FOREIGN KEY constraint "FRGCAD_UPLOAD1" on table "CAD_UPLOAD"
Foreign key reference target does not exist
violation of FOREIGN KEY constraint ""
SQL Code = -530
Firebird Code = 335544466
: INSERT INTO "CAD_UPLOAD" ("CAMINHO_CONTENT_TYPE", "CAMINHO_FILE_NAME",
"CAMINHO_UPDATED_AT", "CAMINHO_FILE_SIZE", "DATCREATE", "ID", "IDNORMA",
"DATUPDATE") VALUES ('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'TESTE.docx',
'2011-09-21 19:17:33', 12716, NULL, 146, 0, NULL)
Model Upload
class Upload < ActiveRecord::Base
set_table_name "CAD_UPLOAD"
belongs_to :sgq_norma, :foreign_key => 'idnorma'
has_attached_file :caminho, :path => ":rails_root/uploads/:id.:extension", :url =>
"/uploads/:id"
validates_attachment_size :caminho, :less_than => 10.megabytes, :message => " - mÃnimo de 10 megabytes
por arquivo"
validates_attachment_content_type :caminho, :content_type => ['application/pdf']
end
Model SgqNorma
class SgqNorma < ActiveRecord::Base
has_many :uploads, :dependent => :destroy, :foreign_key => 'idnorma'
accepts_nested_attributes_for :uploads, :reject_if => lambda { |a| a[:caminho].blank? }, :allow_destroy =>
true
set_table_name "SGQ_NORMA"
set_primary_key "id"
alias_attribute :id, :sgq_norma
def id
self[:id].to_i
end
end
CAD_UPLOAD confirmed in the table that is really foreign_key IDNORMA and SGQ_NORMA ID of the table is a database trigger
the application of this is old |