Hacker News new | ask | show | jobs
by collyw 3649 days ago
In most cases its smaller (in the Django ORM anyway).

myobject, created = MyObject.objects.get_or_create(field1='1' , field2=field2)

That would take a number of lines. One query to check if the object exists, another to create it / retrieve it, plus application code to deal with that SQL.

1 comments

Ok, for this particular example, is operation wrapped in transaction? How will code evalute if we need to check some condition on field2 and occasionally update it?