How to restrict the model to create one record per day?

Business Logic: A user can only create one journal entry per day. Before a record can be created, it must query the records to determine if the record has already been created to date.

I was looking for tips on how best to approach this. I had several ideas on how to implement it on the client side, but I would really like it to be tested at the model level. Any help would be appreciated.

+4
source share
1 answer

Create a unique index in the log table:

add_index :journal_entries, [:user_id, :created_on], unique: true

user_id , , . , created_on date, datetime.

100% , .

+6

Source: https://habr.com/ru/post/1533981/


All Articles