get_or_create method for entities
See original GitHub issueA 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:
- Created 8 years ago
- Reactions:22
- Comments:10
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Has this been implemented yet? This seems like something that would come out of the box
Really need this one