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

  • SEARCH
  • Home
  • 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 7537755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:56:14+00:00 2026-05-30T06:56:14+00:00

Ok I have a messages table: +—–+———–+————–+————–+———–+——–+————–+————–+ | id | sender_id | recipient_id |

  • 0

Ok I have a messages table:

+-----+-----------+--------------+--------------+-----------+--------+--------------+--------------+
| id  | sender_id | recipient_id | body         | parent_id | status | created_at   | updated_at   |
+-----+-----------+--------------+--------------+-----------+--------+--------------+--------------+
| 220 | 4         | 1            | hi           | 220       | 0      | 2012-02-1... | 2012-02-1... |
| 221 | 1         | 4            | hey          | 220       | 0      | 2012-02-1... | 2012-02-1... |
| 222 | 4         | 1            | hi           | 220       | 0      | 2012-02-1... | 2012-02-1... |
| 223 | 1         | 4            | hi           | 220       | 0      | 2012-02-1... | 2012-02-1... |
| 232 | 1         | 4            | good         | 220       | 0      | 2012-02-1... | 2012-02-1... |
+-----+-----------+--------------+--------------+-----------+--------+--------------+--------------+

I’m trying to work out a way to set a message that’s deleted. I figured out that one status column wouldn’t be enough because if 1 use set status to 1 which equals delete then the message would be deleted for both users.

So I decided to create a migration to add sender_status and recipient_status in my messages table and then remove the status column.

I have an update_attribute method in my destro action of my control which updates the specific column when the the delete link is clicked. I will eventually add some more code to destroy the whole message but only when both sender and recipients status’s both equal 1.

My controller action:

def destroy
  @message = Message.find(params[:id])
  @message.update_attribute('sender_status', 1) if @message.sender_id == current_user.id
  @message.update_attribute('recipient_status', 1) if @message.recipient_id == current_user.id
  flash[:success] = "Message deleted"
    redirect_to :back
  end

This helps set either the sender or recipient status. I have this in my controller also:

  def show
    @current_thread = MessageThread.where('sender_id = ? OR recipient_id = ?', current_user.id, current_user.id).where(:message_id => params[:id]).first

    @current_thread_messages = @current_thread.message.children.where(:sender_status => 0, :recipient_status => 0)

  end

So as long as status’s for message rows are 0 the message will show. Right now when I delete a message it is still not shown for both users in the conversation thread.

I can’t seem to figure out a clean way to make this delete illusion work. Mayve a status column has to be permanently linked up with the user or maybe I need a separate column for status’s but then things will get messy. That would be an extra table where i’d have to store more message_id’s.

I would really appreciate help from some experts here.
Kind reagrds

  • 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-30T06:56:15+00:00Added an answer on May 30, 2026 at 6:56 am

    For my reading of your code, you’re almost there. As far as I can tell, it’s just this line that’s keeping your new system hung up:

    @current_thread_messages = @current_thread.message.children.where(
        :sender_status => 0,
        :recipient_status => 0
    )
    

    ‘Cause that’s forcing the message to not be deleted for both users, and that’s the old behaviour. An uglier but more conditional where call should give you what you want:

    @current_thread_messages = @current_thread.message.children.where([
        '(sender_id = ? AND sender_status = 0) OR (recipient_id = ? AND recipient_status = 0)',
        current_user.id,
        current_user.id
    ])
    

    Hope that helps!

    PS: Apologies for any syntax bugs – I’m still on Rails 2.3, so I’m just guessing that things stayed mostly the same…

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

Sidebar

Related Questions

I have a mysql table containing messages: id (INT) sender_id (INT) recipient_id (INT) sent_time
I have a messages table which looks like this: +------------+-------------+----------+ | sender_id | created_at
well i have this messages table with sample values like these: msg_id recipient_id read
I have this in a MySQL db: table Message sender_id int recipient_id int created
I have a column in my database's messages table. It is called status and
I have tables as below. Table Messages message_id parent_id forum_id user_id Table Users user_id
i have a stack of messages in database table. i want to send these
I have an Oracle table which contains event log messages for an application. We
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have this kind of table for simple chat: messages table structure +----+---------+-----------+---------+------+------+ |

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.