I want to manually set value to field "ID" in my table which is not a primary key. Everytime I use the .id attribute and assign value to it, it gets assigned to the primary key (abc_id) but not "id"
table/model: MyModel
primary key: abc_id
another column: id
i tried following ways of saving an ID but none of them seemed to work.
test = MyModel.new
test.id = 555
==> updates abc_id
test.write_attribute(:id, 555)
==> private method not available
test.update_attribute(:id,555)
==> updates abc_id -->ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "id" violates not-null constraint
test.attributes = {id: 555}
==> no error but doesn't do anything
test.send(:attributes=, id: 555)
==> saves other attributes but not id
=> nil
How can I assign value to "id" since I always get PG::NotNullViolation: ERROR: null value in column "id" violates not-null constraint
error while trying to save the record