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

Can't figure how to make this work with seeds.ex #14

Closed
keslert opened this issue Jan 12, 2016 · 4 comments
Closed

Can't figure how to make this work with seeds.ex #14

keslert opened this issue Jan 12, 2016 · 4 comments

Comments

@keslert
Copy link

keslert commented Jan 12, 2016

I'm trying to populate my database with some fake data and I want it to point at a previously uploaded image, but I keep getting errors. What's the proper way to make this happen?

@stavro
Copy link
Owner

stavro commented Jan 21, 2016

If you have an uploaded image on S3 which you want to reference directly, you should not use primary keys of the model to store the files, as these could change every time you seed. I would instead use a uuid as the filename / path.

Then, during the seed file, I would set the avatar attribute directly, rather than going through an upload process.

user = Repo.get! User, 1

user |> Ecto.Changeset.change(avatar: "ccfba165-aa01-4640-a2c7-a580a9a3bb4a.png?v=63620622730") |> Repo.update!

Did you find a different approach to take?

@keslert
Copy link
Author

keslert commented Jan 23, 2016

@stavro No such luck. I've just been skipping images for now. I tried your suggestion but I'm stil getting the following errors: https://gist.github.com/keslert/c93e46def689e79ca8d5.

I tried inserting the book by itself and then doing the update and it gives the same error. This is my BookImage implementation: https://gist.github.com/keslert/445671bf256622319f84

@stavro
Copy link
Owner

stavro commented Jan 24, 2016

Sorry, try this:

book = Repo.get! Book, 1
book |> Ecto.Changeset.change(
  image: %{file_name: "tea_rex.jpeg", updated_at: Ecto.DateTime.utc}
) |> Repo.update!

@keslert
Copy link
Author

keslert commented Jan 28, 2016

Awesome, that did it. Thanks!

@keslert keslert closed this as completed Jan 28, 2016
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

2 participants