Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using EctoStateMachine removes Ecto.Changeset functions from the model #19

Open
davidrichards opened this issue Sep 30, 2016 · 1 comment

Comments

@davidrichards
Copy link

By defining a state machine on a model, I can non longer define a changeset in my model. If I import Ecto.Changeset after I've defined my state machine, things tend to work well again.

I've included examples of what should fail and succeed here: https://gist.github.com/davidrichards/694c7eb030c01b17b014cbaea3aad4f1

The error I get is something along the lines of:

== Compilation error on file web/models/invitation.ex ==
** (CompileError) web/models/invitation.ex:77: undefined function cast/3
    (stdlib) lists.erl:1338: :lists.foreach/2
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

This is the error I get from my own project, not the gist I created above.

Bottom line, I think by aliasing the Ecto.Changeset inside the macro we are changing the way we need to write changesets in our models for non-state changes. To get the import to work again after using the macro, I either have to import Ecto.Changeset again (as in the second example in the gist) or use Changeset.cast(...), Changest.put_change(...), etc.

If there's a way to make that macro less obtrusive to it's surrounding model, that would be useful.

Thanks for this work, btw.

@sitch
Copy link

sitch commented Mar 29, 2017

Just need to not call alias Ecto.Changeset in the macro. You can also just move your use MyApp.Web, :model to after the use EctoStateMachine ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants