Using Deligate in ActiveRecord to Avoid Dots
Adding deligate method in the model
There are various situations where we might be using methods from the child model from its parents model.
Common example is user and posts
1 2 3 4 5 6 7
To make a call to find a post with category ‘ruby’ for a User
If this is being used in multiple places, adding a deligate will make our life easy, thereby avoiding mulitple dots. Also User model doesnt have to know the inner methods of the posts model and a logic change in the model Post would not require multiple changes
1 2 3 4
now the following code will work.
There is an option to allow prefix as well
Any questions on this, please feel free to ask. We’re here to help…