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

Validate parameters #27

Open
gabrielpra1 opened this issue Jun 28, 2019 · 1 comment
Open

Validate parameters #27

gabrielpra1 opened this issue Jun 28, 2019 · 1 comment

Comments

@gabrielpra1
Copy link
Member

Add guard clauses to obtain better error messages.

For example, get_with_assocs passing the struct instead of ID gives

     ** (Ecto.Query.CastError) deps/ecto/lib/ecto/repo/queryable.ex:373: value `%Sppyns.Transactions.FundTransaction{__meta__: #Ecto.Schema.Metadata<:loaded, "fund_transactions">, amount: #Decimal<1>, fee: #Decimal<0.01>, fund: #Ecto.Association.NotLoaded<association :fund is not loaded>, fund_id: 3009, id: 1965, inserted_at: #DateTime<2019-06-28 18:10:26Z>, number_of_tokens: #Decimal<0.99>, operations: #Ecto.Association.NotLoaded<association :operations is not loaded>, transferred: nil, type: :invest, updated_at: #DateTime<2019-06-28 18:10:26Z>, user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 5457, valuations: #Ecto.Association.NotLoaded<association :valuations is not loaded>}` in `where` cannot be cast to type :id in query:
@gabrielpra1
Copy link
Member Author

From the ecto docs:

@primary_key - configures the schema primary key. It expects a tuple {field_name, type, options} with the primary key field name, type (typically :id or :binary_id, but can be any type) and options. It also accepts false to disable the generation of a primary key field. Defaults to {:id, :id, autogenerate: true}.

So if anything can be a PK, I don't think it's possible to add any validation here

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

1 participant