无法查询 one_to_many 与 Sequel gem 的关系?
Can't query one_to_many relationship with Sequel gem?
我在 Postgres 数据库上使用 Sequel gem(使用 Ruby)。
我在 class "Home" 和 class "Person" 之间有 one_to_many 关系。所以,很多人都在一个家里。
我的 class 架构定义如下:
class Home < Sequel::Model
one_to_many :person
end
class Person < Sequel::Model
many_to_one :home
end
我选择了一些人 (p = Person.where(:age => 20)
),现在我正在尝试使用 Home.where(:persons => p)
查询这些人所在的房屋。但是,我收到错误 column "persons" does not exist
.
有什么想法吗?
首先改变你的模型one_to_many :persons
。并用这个收集你的家:
p.map { |person| person.home }
我在 Postgres 数据库上使用 Sequel gem(使用 Ruby)。
我在 class "Home" 和 class "Person" 之间有 one_to_many 关系。所以,很多人都在一个家里。
我的 class 架构定义如下:
class Home < Sequel::Model
one_to_many :person
end
class Person < Sequel::Model
many_to_one :home
end
我选择了一些人 (p = Person.where(:age => 20)
),现在我正在尝试使用 Home.where(:persons => p)
查询这些人所在的房屋。但是,我收到错误 column "persons" does not exist
.
有什么想法吗?
首先改变你的模型one_to_many :persons
。并用这个收集你的家:
p.map { |person| person.home }