ecto_fixtures,预紧关联

时间:2018-11-23 20:12:01

标签: elixir ecto

我在测试Elixir / Phoenix应用程序时尝试使用ecto_fixtures(https://github.com/DockYard/ecto_fixtures)。我面临的挑战是我需要预加载关联,但是我对从fixtures文件创建模型的过程没有任何控制。到获得给定灯具的结果模型时,尚未加载其关联的模型。我希望他们可以预装好并准备黄金时段。

当前,当我这样定义灯具时,

在basic_models.exs文件中:

basic_models model: MyApp.BasicModel, repo: MyApp.Repo do
  basic_model_one do
    name("A Fake Name")

    other_model(fixtures(:other_models).other_model.email)
  end
end

在文件other_models.exs中:

other_models model: MyApp.OtherModel, repo: MyApp.Repo do
  other_model do
    email("fake@email.com")
  end
end

我的测试上面当然有一个标签,像这样:

@tag fixtures: ["basic_models"]
test "a test", %{data: data} do 
  some code
end

在测试中,data.basic_models.basic_model_one.other_model的值为#Ecto.Association.NotLoaded<association :other_model is not loaded>

我看不到任何预加载该关联的方法,理想情况下是这样,这样我就不会玩游戏来处理我的灯具数据。也许是预加载关联的选项。

谢谢!

0 个答案:

没有答案
相关问题