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 3442756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:42:28+00:00 2026-05-18T08:42:28+00:00

Damn you short titles! :p Basically I have an entity named threads and I

  • 0

Damn you short titles! :p

Basically I have an entity named “threads” and I have an entity named “messages”. I have a one to many relationship from threads ->> messages (and a one to one inverse relationship).

What I need to do is get all the records from the threads entity and for each one I need to get the message with the latest timestamp (this is just an int in the “lastUpdated” attribute, so the highest number I guess will suffice).

I’m not sure what other information you may want, here is a screenshot of my entities:

alt text

I’m sure there must be a better way than iterating through all the records and comparing the threadIds?

Thank you.

  • 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-18T08:42:29+00:00Added an answer on May 18, 2026 at 8:42 am

    Once you have the individual Thread objects, you just need to do a sort on the Messages objects and take the topmost Message object.

    The easiest solution would be to create a method in the Thread class like this:

    - (Messages *) lastUpdatedMessage{
        NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"lastUpdated" ascending:NO];
        NSArray *sortedMessages=[self.messagesInThread sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
        return [sortedMessages objectAtIndex:0];
    }
    

    Then all you have to do is ask each Thread object for its lastUpdatedMessage.

    A more complex but more efficient solution would be to create an intermediate linking entity that would link one Message object to one Thread object and set that link object as the Message objects update. So:

    MessageThreadLink{
        message<--(required)-->Message.lastUpdateLink
        thread<--(required)-->Thread.lastUpdatedMessage
    }
    

    Whenever a Message object updated, it would tell it’s related Thread object to delete the existing link object and create another one pointing to it. You would probably put that code in a custom setter for the lastUpdated property.

    With this method you just have to ask each thread for its lastUpdatedMessage and it appears automatically without a lot of searching and sorting.

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

Sidebar

Related Questions

I have spent many hours trying to work this damn thing out! so I
I have this one working but it is so damn slow on jpeg images
I'm just getting acquainted with Vim's CTags functionality - and it's damn handy. One
I'd like to have a small (not doing too damn much) daemon running on
I have some differential equations that I need to solve using MATLAB's ODE solvers.
This is so damn simple im sure! Im missing something and im exhausted from
I have lots of objects. I should evaluate one of thier members.them one by
I have following code. Damn, I stuck with this, I know that is very
So I'm a slightly seasoned php developer and have been 'doin the damn thing'
Yes this is one of the Doh! Damn! I shot myself in the foot.

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.