与我的other question类似,但在这种情况下,我希望获得作者的模式及其关联(Books)。这是我的代码的样子:
require 'sequel'
require 'json'
db = Sequel.connect('postgres://localhost/testing');
class Sequel::Model
self.plugin :json_serializer
end
class Author < Sequel::Model(:author)
one_to_many :books
end
class Book < Sequel::Model(:book)
end
但是当我Author.db_schema
时,我只会获得作者类的信息......而不是它所包含的关联。
{
:id=>{
:oid=>23,
:db_type=>"integer",
:default=>"nextval('author_id_seq'::regclass)",
:allow_null=>false,
:primary_key=>true,
:type=>:integer,
:ruby_default=>nil
},
:name=>{
:oid=>1043,
:db_type=>"character varying",
:default=>nil,
:allow_null=>true,
:primary_key=>false,
:type=>:string,
:ruby_default=>nil
}
}
是否有可能表明至少与Book有某种关联,如果可能,可能会将这些信息包含在Author模式中?类似this的内容。
答案 0 :(得分:1)
您可能希望调用Author.all_association_reflections
来获取关联的元数据(db_schema
只提供列架构元数据)。有关续集反射方法的详细信息,请参阅http://sequel.jeremyevans.net/rdoc/files/doc/reflection_rdoc.html。