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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:11:14+00:00 2026-05-16T17:11:14+00:00

I have a model with a reference property, eg: class Data(db.Model): x = db.IntegerProperty()

  • 0

I have a model with a reference property, eg:

class Data(db.Model):
    x = db.IntegerProperty()

class Details(db.Model):
    data = db.ReferenceProperty(reference_class = Data)

The data reference can be None.

I want to fetch all Details entities which have valid data, ie for which the reference property is not None.

The following works:

Details.all().filter('data !=', None).fetch(1000)

However, according to the documentation on queries, a != query will actually perform two queries, which seems unnecessary in this case. Is != optimised to only perform one query when used with None?

Alternatively, this post mentions that NULL always sorts before valid values. Therefore the following also appears to work:

Details.all().filter('data >', None).fetch(1000)

Although this would only do one query, using > instead of != makes the intent of what it is doing less obvious.

As a third option, I could add an extra field to the model:

class Details(db.Model):
    data = db.ReferenceProperty(reference_class = Data)
    has_data = db.BooleanProperty()

As long as I keep has_data synchronised with data, I could do:

Details.all().filter('has_data =', True).fetch(1000)

Which way would be best?

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-16T17:11:14+00:00Added an answer on May 16, 2026 at 5:11 pm

    I would advise you to use the extra model field. This is more flexible, since it also allows you to query for Details that have no Data references. In addition, queries can only have one inequality filter, so you’re better off saving this inequality filter for another property where inequality makes more sense, such as integer properties.

    To make sure the flag is always updated, you can add a convenience function to Details, like so:

    class Details(db.Model):
        data = db.ReferenceProperty(reference_class=Data)
        has_data = db.BooleanProperty(default=False)
    
        def add_data(self, data):
            """ Adds data"""
            if not data: return
            self.has_data = True
            self.data = data
            return self.put()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 527k
  • Answers 527k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer int value = 12345; string alphabet = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"; var stack… May 16, 2026 at 10:47 pm
  • Editorial Team
    Editorial Team added an answer As you're assuming most people will be using WiFi, I… May 16, 2026 at 10:47 pm
  • Editorial Team
    Editorial Team added an answer I have found out the solution. Have a look the… May 16, 2026 at 10:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I currently have a bookings model such as: public class RoomBooking : Entity, IBooking
As a hypothetical example, I have a model TodoItem and a model TodoList. An
I have 6000 data of district, subdistrict. I need to represent this on dependent
I have a column of type object in a model. But if I load
In my project I have the following helper method, which goes through all the
In C# ASP.NET MVC application I use Link to SQL to provide data for
I'm trying to write my Domain Model as persistence-ignorant as possible . The only
I have been puzzling over a problem this morning with LinqToSQL. I'll try and
Ok, so i have a few <div1> elements with static content inside of them.
I have an entity with a selfreferencyproperty and I wanted to search with a

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.