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

Create fails for abstract / polymorphic tables #81

Closed
novaugust opened this issue Dec 30, 2015 · 3 comments
Closed

Create fails for abstract / polymorphic tables #81

novaugust opened this issue Dec 30, 2015 · 3 comments
Labels

Comments

@novaugust
Copy link

Using polymorphic associations and passing the assoc_id to build/2 allows me to build records, but create fails as its trying to build with the abstract table name rather than the concrete one. The fun thing is, I can manually pipe whatever was built into a Repo.insert! and my insertion is successful.

# factory
  def factory(:vendor_image) do
    name = sequence(:filename, &"file-#{&1}.jpg")
    build_assoc(%Vendor{}, :images, [
      filename: name,
      alt: "Caption text for #{name}",
      medium: "priv/images/medium-#{name}",
      original: "priv/images/original-#{name}"
    ])
  end
# usage..
v = Factory.create(:vendor)

# fails, because its attempting to insert into the abstract table
i = Factory.create(:vendor_image, assoc_id: v.id)
# succeeds 
i = Factory.build(:vendor_image, assoc_id: v.id) |> Repo.insert!
@paulcsmith
Copy link
Contributor

Thanks for submitting the issue.

I'll have to take a look at this next week. We may want to wait until Ecto 2.0 is finished because I think it will handle a lot of these edge cases automatically and it looks like it is coming along nicely. I'll post here with news.

@paulcsmith paulcsmith added the bug label Feb 10, 2016
@paulcsmith
Copy link
Contributor

@novaugust This should be fixed in master. ExMachina now supports Ecto 2.0.0 (which is still in beta) and it should fix the issue you are having. If it doesn't please reopen the issue :D

@novaugust
Copy link
Author

awesome, thanks for the ping. we've worked around it for now, so upgrading + reimplementing won't be at the top of our priorities for a bit, but i'll definitely hit you back when we do it
(cc @jthopple)

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

No branches or pull requests

2 participants