Skip to content

Instantly share code, notes, and snippets.

@chanks
Created August 2, 2011 04:14
Show Gist options
  • Save chanks/1119590 to your computer and use it in GitHub Desktop.
Save chanks/1119590 to your computer and use it in GitHub Desktop.
Annoying bug in Sequel
require "sequel"
DB = Sequel.sqlite
DB.create_table :users do
primary_key :id
end
DB.create_table :quizzes do
Integer :user_id
Integer :number
primary_key [:user_id, :number]
foreign_key [:user_id], :users
end
DB.create_table :pages do
Integer :user_id
Integer :quiz_number
Integer :number
primary_key [:user_id, :quiz_number, :number]
foreign_key [:user_id, :quiz_number], :quizzes
foreign_key [:user_id], :users
end
class User < Sequel::Model
one_to_many :quizzes
end
class Quiz < Sequel::Model
unrestrict_primary_key
many_to_one :user
one_to_many :pages, :key => [:user_id, :number]
end
class Page < Sequel::Model
unrestrict_primary_key
many_to_one :quiz, :key => [:user_id, :quiz_number]
end
user = User.create
user.add_quiz(:number => 1).add_page(:number => 1)
user.quizzes_dataset.eager_graph(:pages).all.first # Works
Quiz.filter(:user_id => 1).eager_graph(:pages).all.first # Fails: Sequel::DatabaseError: SQLite3::SQLException: ambiguous column name: user_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment