Hacker News new | ask | show | jobs
by NeutralForest 1907 days ago
I haven't used Django except as an ORM and it was a terrible experience. Anytime I wanted to update an existing relationship, it was a pain. I've heard a lot of good stuff about it when used as a web framework but I was really baffled by the ORM.
2 comments

What was so painful about it? Unless you're making some really significant changes to your models, Django's migration commands handle 99.9% of cases including most common edge cases. I can't imagine it being any easier, and certainly haven't seen any other web frameworks handling migrations any better.
I just tried to add a new attribute to a many-to-many relationships
I've found the Django ORM to be, in my own opinion, one of the easiest ORMs to hit the ground running with. What was the confusing aspect of updating relational data for you?
Creating relationships was not a problem but for example, adding new fields to an already created many-2-many was an issue. Changing migration scripts was also a hassle.
I have run into this exact problem. A many-to-many table had a business meaning, not just an "invisible" relationship. We wanted to put a model in front of it & add soft deletes and created-at/updated-at fields, at it was a mess of hoops and hacks to jump through.
Does this go easier in any other ORM/DBs that you might have used? Sounds like the semantics of the real-world stuff didn't quite match up to the DB semantics.
We rolled a simple repository pattern library that fit over the SQLAlchemy Table API (no ORM objects, only tables).

Actually writing the the tables was very freeing, no more separation and surprises in the translation between a single model and the multiple tables it can create.

For each new object, we wrote a SQLAlchemy Table object, a domain entity object, and optionally an adapter if you need to map field names between the two. The 300 lines of repo library code did the rest.

A little boilerplate, but no need for a ton of impenetrable, hyper-dynamic ORM code.

Alembic can autogenerate migrations from the SQLALchemy Table objects