Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

column reference "created_at" is ambiguous #14

Open
HenryYan2012 opened this issue Jan 5, 2021 · 0 comments
Open

column reference "created_at" is ambiguous #14

HenryYan2012 opened this issue Jan 5, 2021 · 0 comments

Comments

@HenryYan2012
Copy link

HenryYan2012 commented Jan 5, 2021

Give the following classes:

class A < ::Sequel::Model
  plugin :bitemporal, version_class: AVersion
end
class AVersion < ::Sequel::Model
  many_to_one :b, class: "B"
end
class B < ::Sequel::Model
  plugin :bitemporal, version_class: BVersion
end
class BVersion < ::Sequel::Model
end

When I do the following query I got PG::AmbiguousColumn: ERROR: column reference "created_at" is ambiguous.

 A.current_versions_dataset.eager_graph(
  b: :current_version
).select(
  Sequel.qualify(:a_versions, :master_id)
)

The cause of the issue is in the following code snippet, It does not specify which table the columns belong to.

def self.current_versions_dataset
  t = ::Sequel::Plugins::Bitemporal.point_in_time
  n = ::Sequel::Plugins::Bitemporal.now
  version_class.where do
    (created_at <= t) &
    (Sequel.|({expired_at=>nil}, expired_at > t)) &
    (valid_from <= n) &
    (valid_to > n)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant