Imma be honest with you, chief

Sequelize's associations confuse the heck out of me

Like I understand what one-to-one, one-to-many, many-to-many relationships in a database are, and I know how I can implement them with just SQL, but the whole thing with belongsTo, hasOne, hasMany, belongsToMany just fly over my head completely

  • 0
  • 1
    you need to spend to experiment and break things and put them back together to really understand it

    or watch some tutorials on use cases, read documentation etc.
  • 1

    As most ORMs use a similar naming... Doesn't matter if it's Doctrine.

    IMHO the doc of Doctrine makes this way easier to grok than other documentation I've read so far.
  • 1
    it sucks a lot, completely obscures what sequelize does in the background but doesn't save you from having to think about it.

    Also I still don't get why they made M2M a directed relationship, both the most obvious manually defined relational model and the SQL generated by Sequelize are completely free from any hierarchy.
  • 1
    If possible, switch to another one. I’ve used a few ORMs and sequelize is easily the worst.
  • 0
    I've not used Sequelize myself, but the way you describe it sounds a *lot* like Eloquent in Laravel, and there's a definite learning curve in that, but honestly the benefits of an ORM really are worth it.

    Key to getting the best out of it is not to treat it as a black box and remember it's just a layer of abstraction on top of your database. It makes some queries more complicated to write, but it also simplifies others, and makes it far easier to resolve N+1 queries.
Add Comment