Hi José, Thanks for the fast response. That doesn't seem to do it however. If I do not preload anything, I get an error message saying that the offers are not preloaded. If I preload the offers, it says the rates are not preloaded, and if I preload everything, with force set to true, the rates are still empty. Is there anything else I can try?
Op donderdag 26 mei 2016 17:07:36 UTC+2 schreef José Valim: > > Try: > > *offers = Repo.preload(shipment, [offers: :rates], force: true)* > > If the association was already loaded, we won't load over it. > > *José Valim* > www.plataformatec.com.br > Skype: jv.ptec > Founder and Director of R&D > > On Thu, May 26, 2016 at 5:05 PM, <[email protected] <javascript:>> wrote: > >> Hello, >> >> I have a many-to-many relationship defined as follows: >> >> * schema "rates" do* >> * many_to_many :offers, Offer, join_through: "offers_rates"* >> * end* >> >> >> * schema "offers" do* >> * many_to_many :rates, Rate, join_through: "offers_rates"* >> * end * >> >> >> The offers_rates table is simply a table that has a offer_id column, and >> a rate_id column. I am saving records as follows: >> >> * Enum.map rates, fn (rate) ->* >> * Offer.changeset(%Offer{rates: [rate]}, %{shipment_id: >> rate.shipment_id, percentage: 1.05})* >> * |> Repo.insert!()* >> * end * >> >> >> For every rate, this is generating an offer. I am association the rates >> with the offer in the changeset. This seems to work as I can see the join >> table being filled properly. When I try to fetch them later, the >> association is empty however: >> >> *offers = Repo.preload(shipment, offers: :rates)* >> >> >> * %Offer{rates: []} * >> >> >> Are these the proper ways of association records and fetching them from >> the database again? Any push in the right direction is greatly appreciated. >> >> Thanks! >> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-talk/90e0e96e-a6ca-4111-b4cc-e9d180b99b6b%40googlegroups.com >> >> <https://groups.google.com/d/msgid/elixir-lang-talk/90e0e96e-a6ca-4111-b4cc-e9d180b99b6b%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/2446ae13-a688-4be1-bdbd-a72bab86673d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
