top | item 34338435

(no title)

zachallaun | 3 years ago

I don’t know what the person you’re responding to is getting at, but I found the article very useful! Exposing the changeset through the context is also useful in LiveViews when dealing with forms — once the changeset is valid, calling the relevant function with the same attrs should succeed.

Re: the sibling comment referring to queries, nothing you’re doing in the article prevents that.

Ecto’s changesets are often an unfamiliar concept, so I wonder if that’s where some confusion is coming from.

discuss

order

nesarkvechnep|3 years ago

I like to use changesets for form validation, for example, but those changesets are different than the ones I use in my public API functions. Most of the time what I present to the user don’t map 1:1 to my Ecto schemas and it doesn’t have to.

gregors|3 years ago

This is going to be an unpopular opinion, but I think it's unfortunate that changesets are tied to the views in Phoenix. It's major leakage of ecto and the inner domain at best and at worst it intertwines various concerns - validation and what's changing. The naming of it gives that design choice away. It it didn't it would probably have a name with "validation" in it somewhere. I'd much rather have domain structs implement a protocol. Maybe that's possible I haven't really looked into it.

However, what you say about having different changesets for validation seems to make a ton of sense to me and has given me some ideas. Thanks.

monooso|3 years ago

Thanks, I'm glad you found it useful.