Gator
Gator

Reputation: 720

How do I define my table owner/schema in my sequel class?

The table I'm trying to query is named is cache.dashboardstats

my model is:

class Dashboard < Sequel::Model(:dashboardstats)
 set_schema do
    set_primary_key :dashboardstatid
  end
end

This creates a select * from "dashboardstats";

How do I define the owner/schema of "cache" so that my query becomes:

select * from cache."dashboardstats";

Upvotes: 2

Views: 892

Answers (1)

Jeremy Evans
Jeremy Evans

Reputation: 12139

You can use a double underscore inside a symbol, or one of the qualify methods to represent a qualified identifier:

:cache__dashboardstats
Sequel.qualify(:cache, :dashboardstats)
:dashboardstats.qualify(:cache)

You would use this in your model code like:

class Dashboard < Sequel::Model(:cache__dashboardstats)
end

Note that I left out your set_schema call. You should never call set_schema unless you are calling create_table or a similar method, as otherwise it does nothing. set_primary_key inside set_schema doesn't do what you think, and Sequel can usually determine the primary key correctly, so it's not normally specified manually.

Upvotes: 5

Related Questions