Elektrine lite

← Feed

@damien@layer8.space

Post #4443869

2026-08-08 09:38 UTC

@hamatti@mastodon.world I encountered this for the first time a few days ago, and I'm confused about the use case for it - why would I ever need to get something that I already have? I.e. if I already have the data to be able to create (if it doesn't exist), doesn't that make the DB query pointless?

Replies (1)

  • @hamatti@mastodon.world 2026-08-08 09:53

    @damien@layer8.space Imagine you have a Bread model and it has a ForeignKey to a BreadType. Then you have a data input of 100 breads of variying BreadTypes. When you go through the list, you'll want to create new BreadTypes for ones that don't yet exist and reference the ones that already do. You don't have to create separate conditional branches to first check if a BreadType exists or not. Does that help?

    Open ##4444190