ruby on rails - How to create record in console - ROLLBACK TO SAVEPOINT active_record_1? -


i'm new rails , not sure error here when trying create cost code:

[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 one "cost_codes" ("cost_codes"."code" = '87678' , "cost_codes"."biller_type" null , "cost_codes"."biller_id" null , "cost_codes"."parent_id" null , "cost_codes"."deleted_at" null) limit 1    (0.2ms)  rollback 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)> 

how come record not save , error message alone provide enough detail know missing? or there else should looking model?

here code costcode model:

    # 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 # 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 

when creating records, have make sure provide foreign keys passes validations.

in case:

you have 2 foreign key constraints:

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

along database-level validations:

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 

so have write create record:

costcode.create(biller: <biller instance>, standard_cost_code: <standardcostcode instance>, code: '87678', name: "hex") 

make sure biller , standardcostcode persist.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -