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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:36:48+00:00 2026-06-15T01:36:48+00:00

I have a model with following structure: Document entity has many Commands Command belongs

  • 0

I have a model with following structure:

  • Document entity has many Commands
  • Command belongs to Document

  • Document has many Tags

  • Tag has many Documents

This is important because of additional table used for this type of relation

Tag has also a type property which is an integer being an enum.

What I try to achieve is to ask CoreData for a Commands that belong to Documents which do not have a relation with a tag of type TagTypeUnwanted, in a single query obviously 🙂

I tried to make a subquery with a predicate:

[NSPredicate predicateWithFormat:@"SUBQUERY(document.tags, $tag, $tag.type == %d).@count == 0", TagTypeUnwanted]

unfortunatelly it tries to join with the middle-table that manages the relation between Document and Tag. So it results in complaining that it cannot find filed ‘type’ there, because it has only Document id and Tag id and this is not what I expected. It looks like it would work for every other relation than many-to-many, in this case however it’s lost.

[NSPredicate predicateWithFormat:@"NOT ANY document.tags.type == %d", TagTypeUnwanted]

this one also doesn’t work as it leaves only NOT in the SQL and it reaults in every Document being found because of relations with many types of tags. So it will always find at least one record where type is NOT type TagTypeUnwanted.

If you like more info or generated SQL or anything, just write it in a comment. Thanks in advance!


Looks like NOT ANY and NONE both are not working in Core Data, as far as I was able to check it is a known issue since 2007, normally you do subquery to workaround this, but it seems like subquery in this case cannot handle many-to-many table

NOT ANY generates: AND NOT (Tag.type == TagTypeUnwanted) so it is only close to how SQL should really look

  • 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-15T01:36:49+00:00Added an answer on June 15, 2026 at 1:36 am

    This is perhaps not very effective, but it might be interesting that the following nested SUBQUERY seems to work:

    [NSPredicate predicateWithFormat:
        @"SUBQUERY(document, $doc, SUBQUERY($doc.tags, $tag, $tag.type == %d).@count == 0) != NULL",
        TagTypeUnwanted]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I have the following model structure: class Group < ActiveRecord::Base has_many :group_products, :dependent =>
I have the following structure: Model public class EventEntry : LogEntry { public EventType
I have a Python project with following directory structure: /(some files) /model/(python files) /tools/(more
I have the following model: public class Tag { public int Id { get;
I have the following model structure class User(db.Model) : nickname = db.StringProperty(required=True) fullname =
I have the following structure: class FeatureType(models.Model): type = models.CharField(max_length=20) def __unicode__(self): return self.type
So I have the following model structure for a django project class RawData(models.Model): user
I have the following project structure: base project (service layer, model) web project webservice
For my Python application, I have the following directories structure: \myapp \myapp\utils\ \myapp\utils\GChartWrapper\ \myapp\model\

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.