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

feat: make application changeset overridable #76

Closed

Conversation

StephaneRob
Copy link

@StephaneRob StephaneRob commented Jun 26, 2020

Give the ability to override OauthApplication changeset/3. The main purpose is to add extra fields to an application without adding an new schema referencing it.

Example :

defmodule MyApp do
    @moduledoc false

    use Ecto.Schema

    use ExOauth2Provider.Applications.Application,
      otp_app: :ex_oauth2_provider

    schema "oauth_applications" do
      field(:description, :string)
      field(:reference, Ecto.UUID)

      application_fields()
      timestamps()
    end

    def changeset(application, params, config \\ []) do
      super(application, params, config)
      |> Ecto.Changeset.cast(params, [:reference, :description])
      # |> additional validations
    end
  end

NOTE: What do you think about running elixir formatter for all files in a specific commit? (#77)

@StephaneRob
Copy link
Author

Actually not really necessary can be also done with the following code:

defmodule MyApp do
    @moduledoc false

    use Ecto.Schema

    use ExOauth2Provider.Applications.Application,
      otp_app: :ex_oauth2_provider

    alias ExOauth2Provider.Applications.Application

    schema "oauth_applications" do
      field(:description, :string)
      field(:reference, Ecto.UUID)

      application_fields()
      timestamps()
    end

    def changeset(application, params) do
      Application.changeset(application, params, otp_app: wh_api)
      |> Ecto.Changeset.cast(params, [:reference, :description])
      # |> additional validations
    end
end

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

Successfully merging this pull request may close these issues.

None yet

1 participant