ruby on rails - Calling destroy on relation in Mongoid many to many relation with helper model does not remove model from List -
i have many many relation user project helper
model. user , project has many user_project_memberships
, user_project_membership
has 1 project , 1 user. when try remove relation project's related_users
(or user's related_projects) data removed database correctly related_users array still has relation data!
def remove_user(uid) rel = self.related_users.where(user_id: uid)[0] if rel rel.destroy self.related_users.delete(rel) # added remove relation manually end end
project.related_users.count
return correct amount of relations project code not doing expected!
project.related_users.each |user| puts user.id end
if project.related_users.count
shows 4
small code above prints hello
5 times!
any appreciated, know happened!
ps : i'm not expert in ruby, it's maybe ruby's problem!
Comments
Post a Comment