Rails3 has_and_belongs_to_many 定制
预订has_and_belongs_to_many
学生
Student has_and_belongs_to_many
BooksStudents 模型中的书籍
我想添加“状态”字段来存储它是否被租用、购买等。并能够选择例如 @student.books.rented
或 @student.books.where(:books_students=>{:status=>2})
可以我用 HABTM 来做吗?
Book has_and_belongs_to_many
Students
Student has_and_belongs_to_many
Books
In BooksStudents model I want to add "status" field to store if it is rented, bought ..etc. and be able to select for example @student.books.rented
or @student.books.where(:books_students=>{:status=>2})
Can I do that with HABTM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK 不,你将需要一个 has_many :through setup..
所以你可以做类似
@student.books
或@student.student_books.where(:status =>2)
AFAIK no, you will need a has_many :through setup..
so you can do something like
@student.books
or@student.student_books.where(:status =>2)