My education app uses single database and has got many users. I have following problem:
When user1
finishes a lesson (lesson model has a column finished with boolean), this lesson is finished ( finished = true
) for all other users.
I would like this lesson was finished for user1 but unfinished for all other users.
In other words, how can I separate changes in database done by user1
from changes done by user2
?
Thanks in advance.
For this one you may use joining table called for example users_lesson_progresses
with has_many :through
or has_and_belongs_to_many
association.
See the docs here https://guides.rubyonrails.org/association_basics.html
The idea is in users_lesson_progresses
table you'll have a separate row for every pair of user and lesson. And after a user finishes a lesson, you create a row for this particular user and this particular lesson and set completed
column value to true. Or after a user starts a lesson you set state
column in users_lesson_progresses
table to started
and after he finishes, you set that column value to finished
. Same for any other user and any other lesson. That's an examples. Your approach may vary but the main idea is the same.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.