Rails console save not saving and is selecting from related table instead -
when testing things in rails console noticed strange thing happening when call record , attempt save it.
2.1.5 :026 > p = workorder.first workorder load (0.4ms) select `work_orders`.* `work_orders` order `work_orders`.`id` asc limit 1 => #<workorder id: 3, client_id: 4, created_at: "2015-06-17 17:12:07", updated_at: "2015-06-17 17:12:07", duedate: "2015-07-17", number: "0221506-003", project_type_id: 2, monthlysequencenumber: "003", projectdescription: "project", status_id: 1, labels_id: nil> 2.1.5 :027 > p.save (0.2ms) begin projecttype load (0.5ms) select `project_types`.* `project_types` `project_types`.`id` = 2 limit 1 (0.1ms) commit => true
why appear performing select on associated object? records not being committed database. missing causes behave in such seemingly strange way?
edit: prompted me start try save records pulled database had identical issue doing
p.delete
and then
p.save
which return true, perform strange select on project type
why appear performing select on associated object?
this possibly caused validation code or callbacks in workorder model.
also records not being committed database. missing causes behave in such seemingly strange way?
you have not modified record, field expect updated updated_at
. possible disable timestamp feature activerecord. have done that? (reference is there way avoid automatically updating rails timestamp fields?)
update
the same thing happens when tested p.delete
followed p.save
, result true
. bug, have not researched enough determine yet.
after quick in activerecord source think happens since have first deleted record (p
), 0 rows in database match record's id (p.id
). means when run p.save
0 rows updated (update instead of insert because record considered persisted). number of rows gets compared false
here 0 != false
returns true
.
Comments
Post a Comment