I am trying to achieve polymorphic behaviour in my rails application.
I have 3 models:
- Customer
- Supplier
- Transaction
Transaction has a Party(either customer or supplier).
I have created a model Party as concern when I am trying to save or update I receive this error.
The models are as follows:
party.rb
module Party
extend ActiveSupport::Concern
included do
has_many :transactions, :as => :party
end
end
customer.rb
class Customer < ApplicationRecord
include Party
....
end
supplier.rb
class Supplier < ApplicationRecord
include Party
....
end
transaction.rb
class Transaction < ApplicationRecord
belongs_to :party, polymorphic: true
....
end
When hit save the params received at server are
Parameters: {"authenticity_token"=>"....", "transaction"=>{"party"=>"4", ...}, "commit"=>"Update Transaction", "id"=>"2"}
Hope someone can figure out the issue. Thanks for your time.
Here is the transactions schemea.
create_table "transactions", force: :cascade do |t|
t.date "date"
t.string "transaction_type"
t.integer "supplier_id"
t.integer "customer_id"
t.string "party_type", null: false
t.bigint "party_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["party_type", "party_id"], name: "index_transactions_on_party_type_and_party_id"
end
