I am trying to record user's activity that user performs. User is associated with 3 models for which I am trying to track his activity.
class User < ActiveRecord::Base
has_many :tasks, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :rating, :dependent => :destroy
end
class Task < ActiveRecord::Base
belongs_to :user
end
class Rating < ActiveRecord::Base
belongs_to :user
end
class Comment < ActiveRecord::Base
belongs_to :user
end
- Task model entry is created whenever user is assiged for a task.
- Rating entry is created when other user gives a rating to that user.
- Comment entry is created when some user comments on his task.
Now I want to list these activities of these 3 models for that user according to recency.
Should I create another table named as user_activity table
and every time create a record in user_activity
that table whenever any record is created in above three models. Or should I take use of above three models and search from these tables for user activity on the fly whenever user activity API is called.
What should be the best approach?
Aucun commentaire:
Enregistrer un commentaire