2017-08-18 7 views
0

私はレールに新たなんだとコストコードを作成しようとするとエラーがここにあるのかわからないです:コンソールでレコードを作成する方法 - ROLLBACK TO SAVEPOINT active_record_1?

[21] pry(main)> CostCode 
=> CostCode(id: integer, biller_type: text, biller_id: integer, position: integer, parent_id: integer, code: text, name: text, updated_at: datetime, long_name_helper: text, deleted_at: datetime, sortable_code: text, created_at: datetime, standard_cost_code_id: integer) 

[22] pry(main)> CostCode.create(code: '87678', name: "hex") 
    (0.3ms) SAVEPOINT active_record_1 
    (0.2ms)   SET LOCAL procore.user_id=''; 
      SET LOCAL procore.company_id=''; 
      SET LOCAL procore.project_id=''; 

    CostCode Exists (0.4ms) SELECT 1 AS one FROM "cost_codes" WHERE ("cost_codes"."code" = '87678' AND "cost_codes"."biller_type" IS NULL AND "cost_codes"."biller_id" IS NULL AND "cost_codes"."parent_id" IS NULL AND "cost_codes"."deleted_at" IS NULL) LIMIT 1 
    (0.2ms) ROLLBACK TO SAVEPOINT active_record_1 
=> #<CostCode:0x007ff4cd938ec8 
id: nil, 
biller_type: nil, 
biller_id: nil, 
position: nil, 
parent_id: nil, 
code: "87678", 
name: "hex", 
updated_at: nil, 
long_name_helper: nil, 
deleted_at: nil, 
sortable_code: nil, 
created_at: nil, 
standard_cost_code_id: nil> 
[23] pry(main)> 

このレコードだけでは、このエラーメッセージを保存していていませんどのように来る知るために十分な詳細を提供私は何が欠けているのですか?それとも、モデルから探していなければならないことがありますか?

# Table name: cost_codes 
    # 
    # id     :integer   not null, primary key 
    # biller_type   :text 
    # biller_id    :integer 
    # position    :integer 
    # parent_id    :integer 
    # code     :text 
    # name     :text 
    # updated_at   :datetime 
    # long_name_helper  :text 
    # deleted_at   :datetime 
    # sortable_code   :text 
    # created_at   :datetime   not null 
    # standard_cost_code_id :integer 
    # 
    # Indexes 
    # 
    # cost_codes_parent_id_index      (parent_id) 
    # idx_cost_codes_on_code_biller_null_parent  (code,biller_type,biller_id) UNIQUE 
    # idx_cost_codes_on_code_biller_parent   (code,biller_type,biller_id,parent_id) UNIQUE 
    # idxcost_codes_biller_id      (biller_id) 
    # index_cost_codes_on_biller_id_and_biller_type (biller_id,biller_type) 
    # index_cost_codes_on_standard_cost_code_id  (standard_cost_code_id) 
    # 

    class CostCode < ActiveRecord::Base 
     class ExistingCostCodesForHolder < StandardError 
     end 

     DEFAULT_COST_CODES = YAML.load_file(Rails.root.join('config', 'cost_codes_17_division.yml')) 

     acts_as_procore_relatable 
     acts_as_tree # but really, it's pro_tree 
     acts_as_paranoid 

     include ChangeEventCostCodesCaching 
     include ExternalDataSupport 
     include ReplicaSupport 

     origin_id_unique_within { |cost_code| ['company_id', cost_code.company.id] } 

     belongs_to :biller, :polymorphic => true 
     belongs_to :standard_cost_code 
     has_one :erp_cost_code, class_name: "Erp::CostCode", foreign_key: :procore_cost_code_id, dependent: :destroy 
     has_many :erp_sync_errors, class_name: 'Erp::SyncError', as: :sync_item, dependent: :destroy 
     has_one :erp_standard_cost_code, through: :standard_cost_code 
     has_many :potential_change_orders 
     has_many :quantity_logs 
     has_many :generic_tool_items 
     has_many :meeting_topics 
     has_many :timecard_entries 
     has_many :budget_forecast_modifications 
     has_many :budget_line_items, :dependent => :restrict_with_error 
     has_many :line_items, dependent: :restrict_with_error 
     has_one :bid_item 
+0

あなたはモデルファイルCostCode.rbをアップロードできますか? – widjajayd

+0

私はそれをいくつか追加することができます。それは巨大なファイルです – user9503053

+0

おそらくあなたのモデルのあなたの妥当性検査ルールから来ることができます – widjajayd

答えて

0

レコードを作成し、あなたはそれがすべての検証を渡すだけでなく、すべての外部キーを提供していることを確認する必要があります。ここでは

はCostCodeモデルからコードです。あなたのケースでは

あなたは2つの外部キー制約があります。ですから、このような何かを記述する必要が

idx_cost_codes_on_code_biller_null_parent  (code,biller_type,biller_id) UNIQUE 
idx_cost_codes_on_code_biller_parent   (code,biller_type,biller_id,parent_id) UNIQUE 

:一部のデータベース・レベルの検証と一緒に

belongs_to :biller, :polymorphic => true 
belongs_to :standard_cost_code 

をレコードを作成します。

CostCode.create(biller: <Biller instance>, standard_cost_code: <StandardCostCode instance>, code: '87678', name: "hex") 

BillerStandardCostCodeが既に保持されていることを確認してください。

関連する問題