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]> 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]. > 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/CAGnRm4JpT3CEV_XmbQa4Vy%3DjTgPov-GTc2GauSAyk3yCwvEtJA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
