Rails 2 中的命名范围
我有两个模型.. Member 和 MemberMeeting 。
会员有_许多会员_会议。
我在 Member 模型中编写了一个named_scope,以便它对member_meetings 执行加入操作。
现在最困难的部分是,
我有一个布尔列 xyz。我需要检查 count(xyz=true) > 1 在named_scope内
I have two models.. Member and MemberMeeting .
Member has_many member_meetings.
I have written a named_scope in Member model such that it does a join operation on the member_meetings.
Now the hard part,
I have a boolean column xyz. I need to check for count(xyz=true) > 1 inside the named_scope
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定要为此提供范围吗?我假设您想要一份拥有多个会议且 xyz 为真的所有成员的列表,对吧?在这种情况下,应该这样做:
Are you sure you want a scope for this? I assume you want a list of all members that have more than one meeting where xyz is true, right? In that case, something like this should do:
将这个named_scope添加到Member应该可以做到:
Adding this named_scope to Member should do it: