Project

General

Profile

How to destroy… with has_many

Added by Willmore BattleShipNet about 6 years ago

I develop a plugin which has a somemodel (that belongs_to :project, belongs_to :user). I would like that when a member (Redmine's model Member) is destroyed so somemodel (that has project_id and user_id the same as that member) is destroyed also. How to do that?

Models `Member(id,project_id,user_id), Project, User` are from Redmine.

To achieve thar I would like to patch Member so that it `has_many :somemodels, dependent: :destroy` but I don't know the right parameters to give to `has_many :somemodels` in memember class.

`has_many :somemodels, dependent: :destroy` alone doesn't work as it tries to search for somemodel by member_id which is not present on the somemodels table and so the no column error occurs.

What would be the right `has_many :somemodels ...` to be added to Member?