Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3854674
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:39:33+00:00 2026-05-19T17:39:33+00:00

a user may belong to several groups. a user may do a review of

  • 0

a user may belong to several groups.
a user may do a review of each group.
users have been deleted from groups without deleting reviews. this causes errors.
when a user logs in i want to delete user reviews for groups to which they no longer belong.
here is the code which isn’t working:

@user  = session[:user]
@group = session[:group]
@urevs = UserReview.find(:all, :conditions => ["user_id = ?", @user.id])
unless @urevs.nil?
    @urevs.each do |r|
        ur  = @urevs.id
        @rv = Review.find(:first, :conditions => ["id = ?", @urevs.review_id])
        @gm = GroupMember.find(:first, :conditions => ["group_id = ? and user_id = ?", @rv.group_id, @user.id])
        if @gm.nil?
            @dest = UserReview.find(:first, :conditions => ["id = ?", ur])
            @dest.destroy
        end
    end
end

I would prefer not to do a mysql query to remove all such instances.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:39:33+00:00Added an answer on May 19, 2026 at 5:39 pm
    @user.user_reviews.destroy_all(["user_reviews.group_id NOT IN (?)", GroupMember.where(:user_id => @user.id).all.map(&:group_id)])
    

    This part can be replaced by a more convenient method @user.groups.map(&:id) if you have such method

    GroupMember.where(:user_id => @user.id).all.map(&:group_id)
    

    Also feel free to replace destroy_all with delete_all if you don’t need to cleanup after the records.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where in a web application a user may need a
I have built a simple Eclipse plugin where a user may use a TableViewer
I have a User class which may or may not have an associated Department.
Duplicate of 249087 I have a bunch of user generated addresses that may contain
I am working on a system that splits users by organization. Each user belongs
I am trying to select all of the users who belong to a group.
There are two classes: User and Question A user may have many questions, and
Essentially what I have is an entity class (Article) and one article may belong
I have photos that belong to collections and users. Photos always belong to a
I have a User and Transaction class Each Transaction logically belongs to a User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.