Skip to content

column reference "created_at" is ambiguous #14

@HenryYan2012

Description

@HenryYan2012

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions