5 ms·
That is very interesting approach! I’ve never worked on a project that doesn’t use AR relationships e.g has_many... at all. Do you have an example app or a blo
by geospeck 6y ago
That is very interesting approach! I’ve never worked on a project that doesn’t use AR relationships e.g has_many...
at all.
Do you have an example app or a blog post exposing this pattern? It would be very interesting to see how this actually works. Thanks you very much for bringing this up!
- amw-zero 6y agoThey aren’t saying to not use has_many. They’re saying to not use the association method that gets put on the AR object from has_many. For example, if a User has_many Posts, they’re saying to avoid calling user.posts. That may seem weird, but the association still has value: for querying. You can still write: User.joins(:posts) for example. The problem with the association methods is that they aren’t really methods because they always execute a query. A lot of longtime Rails developers get tired of the database being involved in every step of the way in a request, because it leads to a lack of separation of concerns.
- Fire-Dragon-DoL 6y agoUnfortunately I don't. I work less and less on the CRUD part of the apps, however as I recommended in another comment, Phoenix (Elixir's alternative to Rails) does that correctly: associations are used for the purpose of querying, not as methods. In combination with isolated validations and the data gateway isolated, it's easy to achieve separation of concerns and have a more maintainable code-base.