-
Notifications
You must be signed in to change notification settings - Fork 50
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
Default values? #4
Comments
Hey, just added support for actually passing any Ecto.Schema option, you need to give a keyword list instead of just a symbol. So for example, the page field would be: page: %{
number: [field: :integer, default: 1],
size: [field: :integer, default: 20]
} Note that if an embedded schema like I've already fixed this in master and the ecto-2 branch. I'm unable to publish the new version to hex.pm but will try later today. Hope this fixes this issue. |
Just for reference, the tests are here |
Wow, that was fast, thanks. |
Hi @vic Again thanks for the new feature. However, I have build some of my app relying on maps and not structs, so I used I tried to change my app to use structs instead, but it revealed another problem: Structs returned by Do you agree that:
I will be happy to help with the implementation. |
Hey @lasseebert Yeah, both things you mentions seem right to me.
As for the structs from So glad you want to help with the implementation :), give it a go. Tell me if you need some help with (my shameful) code. Cheers. |
It seems that we do need a AFAICS, the primary key is set when the adapter saves the schema to a datastore, which I think will not happen in the use case of this package. Would it be ok with you that
|
I'm ok with both, go ahead with it, thank you very much :) Btw, should |
I think to_map is a good name. On Tue, Jun 14, 2016, 03:35 Victor Hugo Borja notifications@github.com
|
@lasseebert merged your PR #5. Looks like ecto-2 will be released next week, when that happens I'm going to make the 2.x branch become master so I guess it's fine if we don't backport your changes to the ecto-1 branch. Thanks for your contribution! |
Thanks for you guidance :) |
Suppress warnings in elixir 1.18
Thanks for a great library. I'm just learning Elixir, so I might miss something obvious here.
Is it possible to somehow specify default values in a schema?
I have something like this:
filter
is not required, but it should default to%{}
.page
is not required, but it should default to e.g.%{number: 1, size: 20}
.sort
is not required, and should default to e.g."id"
I could of course write a function that adds the default values, but since
Ecto.Schema
supports this it could be nice to somehow specify it directly in the schema.The text was updated successfully, but these errors were encountered: