Reputation: 27855
I have a table and a view based on the table:
require 'sequel'
db = Sequel.sqlite
db.create_table(:t1){
String :f1
String :f2
}
db.create_view(:v1, db[:t1].select(:f1))
If I create a dataset based on the table, the field name in the dataset an table are the same (:f1
):
sel = db[:t1].select(:f1)
p sel.sql #"SELECT `f1` FROM `t1`"
p sel.columns#[:f1]
But if I do the same with the view, the column name is changed from :f1
to :"'f1'"
(see the code example for correct value, I have to modify a bit for markdown)
sel = db[:v1].select(:f1)
p sel.sql #"SELECT `f1` FROM `v1`"
p sel.columns #[:"`f1`"]
How can I avoid this behaviour?
My environment:
Upvotes: 0
Views: 60
Reputation: 1293
I tried your code in the rails console in a new rails app (3.2.15) with sequel added (4.6.0) and I did not see that behavior. Not sure what, but something is borked on your installation:
db = Sequel.sqlite
# => #<Sequel::SQLite::Database: {:adapter=>:sqlite}>
db.create_table(:t1){
String :f1
String :f2
}
# => nil
db.create_view(:v1, db[:t1].select(:f1))
# => nil
sel = db[:t1].select(:f1)
# => #<Sequel::SQLite::Dataset: "SELECT `f1` FROM `t1`">
p sel.sql
# "SELECT `f1` FROM `t1`"
# => "SELECT `f1` FROM `t1`"
p sel.columns#[:f1]
# [:f1]
# => [:f1]
sel = db[:v1].select(:f1)
# => #<Sequel::SQLite::Dataset: "SELECT `f1` FROM `v1`">
p sel.sql
# "SELECT `f1` FROM `v1`"
# => "SELECT `f1` FROM `v1`"
p sel.columns #[:"`f1`"]
# [:f1]
# => [:f1]
Upvotes: 1