【发布时间】:2015-01-22 14:14:43
【问题描述】:
我有两个模型:
富:
class Foo < Sequel::Model (:FOO_TABLE)
set_primary_key [:KEY]
# has many Bars
one_to_many :bars
end
酒吧:
class Bar < Sequel::Model (:BAR_TABLE)
# compound key
set_primary_key [:KEY,:NBR]
# belongs to Foo
many_to_one :foo
end
加载 Foo 按预期工作:
irb> foo = Foo['ABC']
=> #<Foo @values={:KEY=>"ABC", :NAME=>"ABC name"}>
但是,当我尝试加载它的 Bars 时,我收到一个错误:
irb> bars = foo.bars
=> Sequel::DatabaseError: Mysql2::Error: Unknown column 'BAR_TABLE.foo_id' in 'where clause'
在我的 Sequel 模型中指定外键的正确方法是什么?
** 编辑 **
使用 MySQL2。
【问题讨论】:
-
您需要设置表的架构以获得适当的帮助。
标签: mysql ruby sequel sequel-gem