0

Hey folks I'm experimenting with the ruby awesome_nested_set gem for the first time.

I'm having an issue with my minitests in a rails-api app. I know what the issue is but am unsure how to fix it at this point.

When I run "rails test" I get a bunch of errors similar to the following: StoresControllerTest#test_should_create_store: ActiveRecord::StatementInvalid: Mysql2::Error: Field 'lft' doesn't have a default value: INSERT INTO categories (name, created_at, updated_at, id, store_id) VALUES ('MyString', '2018-02-23 03: 08:13', '2018-02-23 03:08:13', 980190962, 980190962)

Here is my Migration: class AddLftToCategory < ActiveRecord::Migration[5.0] def change add_column :categories, :lft, :integer, :null => false add_index :categories, :lft end end

I believe the issue is a result of my migration setting ":lft, :null => false. This makes the most sense, but how can I fix this? Do I need to add something to my fixture, or is there something else I must do?

Thanks.

user2593486
  • 55
  • 1
  • 8

1 Answers1

0

after reading the docs for the gem, it’s apparent that your migration is incomplete. your category needs to have a :rgt column as well as the :lft, :name, and :parent_id for the gem to work. see the docs here: (https://github.com/collectiveidea/awesome_nested_set/blob/master/README.md). you also need to add acts_as_nested_set to your model for these fields to be populated by the gem.

Pdeona
  • 1
  • 1
  • Unfortunately I already have all that. Running via Spring preloader in process 13499 Loading development environment (Rails 5.0.6) 2.4.1 :001 > Category.new => # 2.4.1 :002 > – user2593486 Feb 24 '18 at 01:05
  • I think its fixed for now. I guess I just had to tell the fixture the correct format of the data with the following: one: id: 1 name: Top Level lft: 1 rgt: 10 child_1: id: 2 name: Child 1 parent_id: 1 lft: 2 rgt: 3 – user2593486 Feb 24 '18 at 01:14