P
P
Pavel Shcheglov2015-12-30 09:52:35
Ruby on Rails
Pavel Shcheglov, 2015-12-30 09:52:35

How to know if the number of records in a model has changed?

Hello.
There is a Product model, this model has pictures, which we can calculate for example like this:
Product.first.pictures.size
The question is how to find out that the number of pictures for a certain product has changed after it was created or updated.
For example, for titles and descriptions, I use the method:

before_update :drop_moderation

def drop_moderation
    self.status = 'on_moderation' if self.title_changed? || self.description_changed?
end

but with pictures using dirty doesn't work, pictures_changed? doesn't work.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question