trailblazer / reform

Form objects decoupled from models.
https://trailblazer.to/2.1/docs/reform.html
MIT License
2.49k stars 184 forks source link

rom-rb support #383

Open solnic opened 8 years ago

solnic commented 8 years ago

Hey folks, I'd like to start a discussion about making Reform work with rom-rb repositories. We added support for commands in repositories, so now storing data in rom looks like this:

user_repo.create(name: "Jane")

Furthermore, we added support for changesets, which ie can look like this:

user = user_repo.create(name: "Jane")
changeset = user_repo.changeset(user.id, name: "Jane Doe")

changeset.diff? # true
changeset.diff # {name: "Jane Doe"}

user_repo.update(user.id, changeset)

^^^ this stuff will be available next week with rom 2.0 release.

It cannot be any simpler than this, so I think it's a good moment to (finally) have Reform baked by rom repos. As I understand, Reform uses Twins that wrap data and provides sync mechanism for making changes in the underlying db. So I guess that'd be the place where we should integrate our lovely libs ;)

Alternatively we could look into making twins work with commands directly but that's gonna be much harder since repositories automatically build commands, even for nested data.

apotonick commented 8 years ago

Awesome!!! :heart_eyes:

Twins were designed to work with classic DB "models". They

  1. read property values from the model(s) as per defined schema
  2. then expose accessors, e.g. twin.email = "solnic@trb.to" which will only change state on the twin
  3. finally offer you twin.sync to write the data back to the model(s).

Would 3. then work via a command? How would we nest commands for nested twins? And: where would we read from existing twins for 1.?

Exciting times!!! :beers: Too bad you couldn't make it to Lviv today, it's warm, sunny, perfect!

cflipse commented 7 years ago

If I'm understanding all of the pieces correctly at the moment -- and I may not be -- I suspect that, presently, the block-save syntax of Reform works better for changesets than twin-synching would.

However, Repositories are also meant to be a high-level bridge between your domain objects and your relations, meaning that what you typically get out of a repository is the domain object you're working with ... which, possibly does work better with the twin-syncing.

At a shallow glance right now, then, it looks like the block-save works with changest style commands, while sync works when you've got the repository structured to accept objects to insert/update.

I have been tinkering with migrating forms using the block-style save, and I have some better experience with that ... but the app that I'm working with at the moment predates rom-repository, so I can't say how well those two pieces fit, though there's certainly some conceptual matching.

Also, for that reason, I'd like to make sure that there's a reform linkup that does not depend on rom-repository :)