question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get_or_create method for entities

See original GitHub issue

A method like get_or_create would be useful to avoid boilerplate code with the following pattern:

@classmethod
def get_or_create(cls, **kwargs):
    r = cls.get(**kwargs)
    if r is None:
        return cls(**kwargs), True
    else:
        return r, False

See also Django’s get_or_create.

I’ve just started looking at Pony ORM, and therefore might have likely missed something.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:22
  • Comments:10

github_iconTop GitHub Comments

9reactions
cercoscommented, Sep 1, 2019

Has this been implemented yet? This seems like something that would come out of the box

5reactions
zhaobenxcommented, Jul 7, 2020

Really need this one

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Is getOrCreate function a good or a bad practice?
In my code (hypothetical) I'd like to use getOrCreate function. I pass the parameters and I either get a new entity or I...
Read more >
GetOrCreate method for a database operation
So, I created one method GetOrCreate and used the transaction. Do you think in that case the GetOrCreate method is a good approach?...
Read more >
IClrCollectionAccessor.GetOrCreate(Object, Boolean) Method
Either returns the existing collection instance set on the navigation property, or if none exists, then creates a new instance, sets it, and...
Read more >
ASP.NET Core MemoryCache - GetOrCreate calls factory ...
ASP.NET Core MemoryCache – GetOrCreate calls factory method multiple times · Exclusive lock over factory method · Lock per key · Lock per...
Read more >
Creating Entities - Cesium
Learn to use the Entity API in CesiumJS for drawing spatial data such as points, markers, ... Either method calculates a view of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found