Skip to content

ActiveRecord::StatementInvalid (null value) on rebuild! #2

Closed
@zlw

Description

@zlw

I've got problem when I'm trying to rebuild hierarchies table. Running User.rebuild! causes this error:
https://gist.github.com/1244628 (tried this on sqlite3 and postgresql)

My model:

class User < ActiveRecord::Base
  # invited_by_id comes from devise_invitable
  acts_as_tree parent_column_name: :invited_by_id
end

Migration file:

class CreateUsersHierarchies < ActiveRecord::Migration
  def change
    create_table :users_hierarchies, id: false do |t|
      t.integer  :ancestor_id, null: false   # ID of the parent/grandparent/great-grandparent/... tag
      t.integer  :descendant_id, null: false # ID of the target tag
      t.integer  :generations, null: false   # Number of generations between the ancestor and the descendant. Parent/child = 1, for example.
    end

    # For "all progeny of..." selects:
    add_index :users_hierarchies, [:ancestor_id, :descendant_id], unique: true

    # For "all ancestors of..." selects
    add_index :users_hierarchies, [:descendant_id]
  end
end

Is this a bug or am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions