elixir - How to duplicate records for Ecto? -


i have couple of ecto records. want duplicate them (make them 100 times bigger) play big amount of records. how can via ecto mechanisms?

you can replicate dup removing id key record:

for n <- (0..10), do: user |> repo.get(record_id) |> map.delete(:id) |> repo.insert 

although won't work if have unique keys... leave needing populate struct yourself:

def spawn_records(line_numbers)   line <- line_numbers     %user{first_name: "tyrone", last_name: "shoelaces#{line}"} |> repo.insert   end end 

if you're thinking of second answer i'd echo dogbert , recommend using ex_machina in dev.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -