Answer the question
In order to leave comments, you need to log in
How to organize "favorites" in Yii2?
Yii2 has a model (Item) containing a small text, similar to "quote" from bash.im, there are about 30,000 of them. There is also a User model. It is necessary to describe the many-to-many relationship "Favorites", so that a user with certain rights (!), Can mark 20-30 elements there (such as "baskets" in stores), when issuing ALL records, elements from the "Favorites" should be added corresponding . classes.
How to organize all this in Yii2, so as not to perform a query to the database to check each record for belonging to the Favorite and at the same time the models remain maximally abstracted from each other?
Answer the question
In order to leave comments, you need to log in
You do many to many, store the last time the favorites were updated in the user profile, keep the list of favorites in a hot cache, for example, redis. When initializing the profile, you remove the list of favorites from the cache, or if there is no cache or it is expired relative to the date in the profile, update it from the database. The cache of favorites will be in the form of arrays of id objects, to determine "favorites" you check the occurrence of the object id in the array.
On what to do - Yii, Django, Rails, Kohana - there is absolutely no difference if you own the toolkit.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question