A
A
Andrey2017-10-04 23:03:59
Ruby on Rails
Andrey, 2017-10-04 23:03:59

Is it possible to rename a foreign key?

Is it possible to remove the prefix _idfrom a foreign key?
New table. two models OrderandProduct

class Order < ApplicationRecord
  has_many :products
end
class Product < ApplicationRecord
  belongs_to :delivery, :class_name => "Order"
end

t.integer :delivery, index: true
I make an error in the products table :
ActiveRecord::AssociationTypeMismatch: Order(#85313090) expected, got 1 which is an instance of Fixnum(#73138750)

How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Andreev, 2017-10-05
@b0nn1e

It is possible through foreign_key, but why does delivery_id not suit you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question