[英]Modeling A Book With Ruby on Rails Active Record
Im modeling an online book with ruby on rails. 我在用红宝石制作的在线书籍上建模。 The book has chapters, each chapter has pages.
这本书有章节,每章都有页面。 Modeling this part is easy.
对这部分建模很容易。 What id like to do is keep track of what pages each user has read and when and whether they liked that page / whether the user completed the book.
id想要做的是跟踪每个用户阅读了哪些页面,何时以及他们是否喜欢该页面/用户是否完成了这本书。 How would one recommend modeling keeping track of this in rails?
如何建议建模以跟踪此情况? Id ideally like to say give me all the books the user is or has read, and then have access to the book plus state info for that user's reading of the book.
理想情况下,Id希望向我提供该用户正在阅读或已经阅读的所有书籍,然后可以访问该书籍以及该用户阅读该书籍的状态信息。
The BookState becomes the intermediate object between the user and the book. BookState成为用户和书之间的中间对象。
class User < ActiveRecord::Base
has_many :book_states
has_many :books, :through => :book_state
end
class BookState < ActiveRecord::Base
belongs_to :user
belongs_to :book
end
class Book < ActiveRecord::Base
has_many :book_states
end
BookState has the current location, the likes/dislikes, etc. If you ask for a user's bookStates, that will give you the books as well. BookState具有当前位置,喜欢/不喜欢等。如果您请求用户的bookStates,那也会给您书籍。
This makes a lot of sense. 这很有道理。 The one problem i see is collecting stats on a question (what percent of the time was this answered)?
我看到的一个问题是收集有关一个问题的统计信息(此问题被回答的时间百分比是多少)? Since that data is in serialized hashes?
由于该数据是序列化的哈希? What about this:
那这个呢:
book
has_many user_books
has_many users through user_books
has_many chapters
chapter
belongs_to book
has_many pages
page
belongs_to chapter
has_many user_pages
user
has_many user_books
has_many books through user_books
user_book
belongs_to user
belongs_to book
has_many user_pages
user_page
belongs_to user_book
belongs_to page
What do you think? 你怎么看?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.