如何使用datamapper根据子表中的某个值进行查询
create table foo (id, name)
create table foo_config (id, foo_id, key, value)
insert into foo (1, 'name1')
insert into foo (2, 'name2')
insert into foo (3, 'name3')
insert into foo_config (1, 1, 'key1', 'val1')
insert into foo_config (2, 1, 'key2', 'val2')
insert into foo_config (3, 1, 'key3', 'val3')
insert into foo_config (4, 2, 'key1', 'val1')
insert into foo_config (5, 3, 'key2', 'val2')
如何查询所有 key1 = 'val1'
的 foo(在我们的例子中为 foo:1) foo:2 将列在这里。我应该如何建模/查询这个, 感谢任何指点。
create table foo (id, name)
create table foo_config (id, foo_id, key, value)
insert into foo (1, 'name1')
insert into foo (2, 'name2')
insert into foo (3, 'name3')
insert into foo_config (1, 1, 'key1', 'val1')
insert into foo_config (2, 1, 'key2', 'val2')
insert into foo_config (3, 1, 'key3', 'val3')
insert into foo_config (4, 2, 'key1', 'val1')
insert into foo_config (5, 3, 'key2', 'val2')
How do I query for all foo's whose key1 = 'val1'
, in our case foo:1
and foo:2 will be listed here. How should I model / query for this,
appreciate any pointers for the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您必须构建模型并设置关联:
以下是设置查询的方法:
First you have to build the models, and set up the associations:
And here is how you would set up the query: