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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to