jackdempsey / sequel_polymorphic

MIT License
37 stars 13 forks source link

Sequel::DatabaseError: PG::UndefinedColumn: ERROR: column "..." of relation "..." does not exist #28

Closed okliv closed 7 years ago

okliv commented 7 years ago

hi!

I have:


class MyGem::User < Sequel::Model

  # plugin :nested_attributes
  # plugin :association_dependencies

  one_to_many :tasks, as: :taskable
  # nested_attributes :tasks
  # add_association_dependencies tasks: :destroy

end

# db columns: ... taskable_type(String), taskable_id(Integer)
class MyGem::Task < Sequel::Model
  many_to_one :taskable, polymorphic: true
end

If i try from console:

$ @user = User.first
$ @task = Task.first
$ @task.taskable = @user
$ @task.save

i receive this:

Sequel::DatabaseError: PG::UndefinedColumn: ERROR: column "taskable" of relation "tasks" does not exist LINE 3: ...ble_id" = 3, "taskable_type" = 'User', "taskable"...

rails-5.1.3 sequel-4.46.0 sequel_polymorphic-0.3.1

and i am stuck :( any thoughts how it can be fixed or, at least, how can i investigate it more deeply - why? thanks

jnylen commented 7 years ago

Weird @okliv, I have several models with that type specifically. Can you try removing Class: 'Task'?

mine (anime):

one_to_many :episodes, as: :media, dependent: :destroy

episode:

many_to_one :media, polymorphic: true

By the way, dont forget to load the plugin: Sequel::Model.plugin :polymorphic globally or plugin :polymorphic in specific models.

okliv commented 7 years ago

no luck...

and i have globally loaded these plugins (in case of possible interference now i will try to disable each of them)

  Sequel::Model.plugin :update_or_create
  Sequel::Model.plugin :many_through_many
  Sequel::Model.plugin :polymorphic
  Sequel::Model.plugin :dirty

upd: i have disabled all of them (except :polymorphic) - error still exists

okliv commented 7 years ago

okay :)

in fact, i have

class MyGem::User < Sequel::Model

and

class MyGem::Task < Sequel::Model

and now i think that problem is somewhere there...

okliv commented 7 years ago

oh... my bad... sorry... finally, i found that in other part of application (custom sequel plugin) there is one before_create callback that distorted object to be saved... callbacks can be a huge headache :(((

jnylen commented 7 years ago

@okliv, Nice that you fixed it! ;)

Welcome to the world of Sequel.