我的Phoenix框架应用程序中有一个post模型。
我想通过我的终端添加记录。在Rails中,我可以在rails控制台中执行以下操作:
u = Post.create title: "My Title", content: "Here's my content..."在IEX中与此等效的是什么?
发布于 2017-08-24 02:40:57
首先,你需要用下面的命令启动你的万灵丹终端
iex -S mix不管你有没有那个-S mix,它都不行。
在iex运行之后,你只需要给你的模块起别名(使它更容易被访问)
alias MyApp.Repo
alias MyApp.Post设置好别名之后,就可以执行任何操作了。只需通过获取所有帖子进行测试:
Repo.all(Post)如果没有错误(UndefinedFunctionError),那么您可以使用以下命令插入数据:
Repo.insert(%Post{title: "My Title", content: "Here's my content..."})希望能对你有所帮助。:D
发布于 2016-04-19 09:18:39
在Phoenix Documentation中找到了答案。
在IEx中,我可以这样做:
post = %MyApp.Post{title: "My Title", content: "Here's my content..."}然后是:
MyApp.Repo.insert post 发布于 2016-04-19 15:21:49
首先,您需要使用以下命令启动phoenix iex:
iex -S mix phoenix.server然后对Ecto执行查询:
post = %MyApp.Post{title: "My Title", content: "Here's my content..."}https://stackoverflow.com/questions/36706819
复制相似问题