【问题标题】:warning: Ecto.Repo.insert_all/3 is undefined or private警告:Ecto.Repo.insert_all/3 未定义或私有
【发布时间】:2020-02-26 23:07:38
【问题描述】:

(请注意:这里是菜鸟,所以请 ELI5,谢谢。)

代码片段:

defmodule Wallet do
    use Ecto.Repo,
    otp_app: :arbit,
    adapter: Ecto.Adapters.Postgres
    alias Ecto.Repo
    #use Genserver

    require ArbitDB.WalletBalance

    def refresh_db do
        updated_balances = liquid_holdings()
        Repo.insert_all(WalletBalance, updated_balances, 
            on_conflict: :replace_all_except_primary_key, conflict_target: :value_USD)
    end



$ iex -S mix
Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Compiling 1 file (.ex)
warning: Ecto.Repo.insert_all/3 is undefined or private

是什么导致了这个警告?正确的解决方法是什么?感谢您花点时间提供帮助:)

【问题讨论】:

    标签: compiler-errors elixir warnings ecto undefined-function


    【解决方案1】:

    Ecto.Repo.insert_all/3 是一个回调。也就是说,它是由 your repo 模块实现的。

    会在她需要将多条记录插入您的存储库时调用它。

    好消息是,如果您不需要一些非常具体的实现,provides a naïve one 适合您(不要被“幼稚”这个词吓到,在 99% 的情况下都可以。)

    也就是说,你需要在 你的 repo 上调用 insert_all/3,它调用 use Ecto.Repo(后一个宏是注入所有 @987654325 的宏@.)


    旁注:我不确定您实际上想要实现什么,其余代码似乎也不一致,但由于 Wallet 是调用 use Ecto.Repo 的人,因此谁在您的应用程序中扮演Repo 的角色,调用Wallet.insert_all/3(或不完全限定insert_all/3,因为我们在同一个模块中)将是进一步挖掘的一个很好的开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 2016-01-14
      • 2013-05-23
      • 1970-01-01
      相关资源
      最近更新 更多