rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.09k stars 161 forks source link

Sequel warning when using primary key #404

Closed AaronBetterOfficeApps closed 7 years ago

AaronBetterOfficeApps commented 7 years ago

I keep getting the following warning from Sequel whenever I try to define a primary key inside of a schema block in a relation.

SEQUEL DEPRECATION WARNING: Symbol splitting is deprecated and will be removed in Sequel 5.  Either set Sequel.split_symbols = true, or change :remote_files__id to Sequel.qualify("remote_files", "id").
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/sequel-4.46.0/lib/sequel/core.rb:256:in `split_symbol'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/sequel-4.46.0/lib/sequel/sql.rb:500:in `expr'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-sql-1.3.1/lib/rom/sql/attribute.rb:107:in `qualified'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-3.2.3/lib/rom/schema.rb:126:in `each'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-3.2.3/lib/rom/schema.rb:126:in `each'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-sql-1.3.1/lib/rom/sql/schema.rb:46:in `map'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-sql-1.3.1/lib/rom/sql/schema.rb:46:in `qualified'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-sql-1.3.1/lib/rom/sql/relation.rb:57:in `block (2 levels) in inherited'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-3.2.3/lib/rom/setup/finalize/finalize_relations.rb:61:in `instance_exec'
/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rom-3.2.3/lib/rom/setup/finalize/finalize_relations.rb:61:in `build_relation'

I tried using both primary_key :id and attribute :id, Types::Int.meta(primary_key: true)

Below if a full code sample that will cause the warning to be raised.

require "rom-sql"
require "rom-repository"
module Relations
  class RemoteFiles < ROM::Relation[:sql]

    schema(:remote_files) do
      attribute :id, Types::Int
      attribute :file_id, Types::String
      attribute :name, Types::String
      attribute :key, Types::String
      attribute :bucket, Types::String
      attribute :region, Types::String
      attribute :version, Types::Int

      primary_key :id
    end

    def by_id(id)
      where(id: id)
    end
  end
end

module Repositories
  class RemoteFiles < ROM::Repository[:remote_files]
    commands :create
    def [](id)
      remote_files.by_id(id).one!
    end
  end
end

config = ROM::Configuration.new(:sql, 'postgres://localhost/read_model', username: 'event_source')
config.register_relation Relations::RemoteFiles
container = ROM.container(config)
flash-gordon commented 7 years ago

Please update rom-sql https://github.com/rom-rb/rom-sql/blob/master/CHANGELOG.md#v132-2017-05-13