-
Notifications
You must be signed in to change notification settings - Fork 146
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
Add params_with_assocs function #124
Conversation
@@ -66,6 +70,33 @@ defmodule ExMachina.Ecto do | |||
|> drop_ecto_fields | |||
end | |||
|
|||
@doc """ | |||
Same as `params_for/2`, but it inserts all associations and sets the | |||
foreign_keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it should only insert the belongs_to
associations and not has_many
. What do you think?
Same as
params_for/2, but it inserts all belongs_to associations and sets the foreign keys
This is awesome! I was actually going to ask if you had time to tackle this next :D |
ec71427
to
01dfce0
Compare
@@ -66,6 +73,50 @@ defmodule ExMachina.Ecto do | |||
|> drop_ecto_fields | |||
end | |||
|
|||
@doc """ | |||
Same as `params_for/2`, but it inserts all belongs_to associations and sets the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be shortened to Same as
params_for/2, but inserts all belongs_to associations and sets the foreign keys
? If you don't like that I'm fine with it as-is as well
A few comments, but this looks really good :) Good to merge whenever you're ready |
@@ -43,14 +43,18 @@ defmodule ExMachina.EctoTest do | |||
end | |||
end | |||
|
|||
test "params_with_assocs/2 inserts belongs_to associations" do | |||
test "params_with_assocs/2 inserts belongs_tos that are set by the factory" do | |||
assert Enum.member?(ExMachina.Article.__schema__(:associations), :editor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, but I think extracting to a private function would be good. Something like assert has_association_in_schema?(ExMachina.Article, :editor)
. What do you think?
7377c3f
to
607d082
Compare
607d082
to
84ccf51
Compare
Addresses: #105