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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:06:51+00:00 2026-06-07T06:06:51+00:00

I have the following data model: Group(name, color, activities*) // one group may have

  • 0

I have the following data model:

Group(name, color, activities*) // one group may have many activities
Activity(startTime, endTime, location, Group*) // startTime and endTime are NSDate, group is an inverse relationship

so if I want to get all Groups who have at least one activity which on on a specified NSDate, say theTime, what predicate should I construct?

My thoughts:

  1. first get all activities
  2. then put their groups into a Set in order to remove duplicate Groups
  3. convert the Set to an array

so:

[NSPredicate predicateWithFormat:@"%@ >= startTime AND %@ <= endTime", theTime]

fetch an array of Activities then:

for (Activity *activity in activities)
{
    [theSet add:activity.group];
}

so I got an array of unique Groups that have at least one activity on theTime?

Is there any other way to just do a fetch without post-processing?

Thanks!

EDIT:

Can I do:

[NSPredicate predicateWithFormat:@"%@ >= activities.startTime AND %@ <= activities.endTime", theTime]

???

  • 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-06-07T06:06:52+00:00Added an answer on June 7, 2026 at 6:06 am

    If I understood well your question, yes.

    You can do it fecthing against Group instead of Activity entity. In this manner you can avoid to fetch first Activityies enitity and then apply a filter. Since activities is not a scalar value, you need a predicate modifier (ANY, ALL, etc.) or a SUBQUERY.

    About your question I would do the following:

    [NSPredicate predicateWithFormat:@"(SUBQUERY(activities, $x, $x.startTime >= %@ and $x.endTime <= %@).@count > 0)", theStartTime, theEndTime];
    

    About the predicate, I suppose yuo want to find Groups that contain Activityies included in a specificified range.

    Try and let me know. Hope that helps.

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

Sidebar

Related Questions

I have the following models: # Group for Key/Value pairs class Group(models.Model): name =
I have the following data model: I am writing a WCF service that needs
I have a SqlServer2005 table Group similar to the following: Id (PK, int) Name
We have the following data model: CalendarAppointment 1 <------> * AppointmentRole * <--------> 1
I have a data model like the following: username | product1 | product2 -------------------------------
I have the following data model: Camp -> CampEvent <- Event. Camp has CampId
I have the following data in my database: |NO | model | date |
If I have the following: {hdrs: [Make,Model,Year], data : [ {Make:Honda,Model:Accord,Year:2008} {Make:Toyota,Model:Corolla,Year:2008} {Make:Honda,Model:Pilot,Year:2008}] }
I have the following data model class defined: @PersistenceCapable public class TestSerializableModelObj { @Persistent(serialized=true,
I have the following data: var data = [ { id: 1, name: 'Ed

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.