has_one :通过 =>多种的
出席和凭证:
belongs_to :event
belongs_to :account
因此:出勤和凭证之间是 1 对 1 的关系。
有没有办法不用我想太多就能做到这一点?
# attendment
has_one :vouching :through => [:event, :account]
注:实际上,我不介意想太多。
Both Attendment & Vouching:
belongs_to :event
belongs_to :account
Therefore: 1 to 1 relationship between attendments and vouchings.
Is there a way to do this without my thinking too much?
# attendment
has_one :vouching :through => [:event, :account]
Note: I don't mind thinking too much, actually.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,我认为你不能为此使用 has_one 。假设我正确地阅读了本文,您有两种模型:
出勤
凭证
它们都存储 event_id 和 account_id。您想从出席模型中了解哪些凭证与出席共享相同的事件和帐户。我认为最简单的解决方案是在 attendment.rb 文件中编写一个方法。
Yeah i don't think you can use a has_one for this. Assuming I'm reading this correctly, you have two models:
Attendment
Vouching
They both store an event_id and account_id. You want to know from the attendment model, what vouching shares the same event and account as the attendment. I think the easiest solution for this is to write a method inside your attendment.rb file.