D
D
Dmitry Amelchenko2018-02-12 11:44:01
Ruby on Rails
Dmitry Amelchenko, 2018-02-12 11:44:01

activerecord-jsonb-association gem not working with belongs_to?

Ticket.last.location returns nil and has_many works. Can anyone come across?

class CreateTickets < ActiveRecord::Migration[5.1]
  def change
    create_table :tickets do |t|    
      t.jsonb :settings
      t.string :name       
      t.timestamps         
    end
  end
end

class Ticket < ApplicationRecord
  belongs_to :location, store: :settings, optional: true
end

Ticket.create! name: "test", settings: {location_id: 1}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question