我将设置存储到一个配置字段中,如下所示:
schema "teams" do
field :owner_id, :integer
field :is_base_team, :boolean
field :config, :map
has_many :team_users, {"team_user", App.TeamUser}
end
因此,我需要构建在config中读取参数config的查询,如下所示:
teams_users =
from(t in Team, where: t.owner_id == ^use
我已经打开了一个bash终端进行编译。然后打开另一个iex终端,打开命令是iex -S mix。
修改前的代码如下:
defmodule Mirror.Imports.Product do
use Ecto.Schema
import Ecto.Changeset
def test do
IO.inspect("hello world")
end
在编译后,代码如下:
def test do
IO.inspect("hello world1")
end
第一个终端中的编译命令如下:
mix compile
我发现在第二个ie
我想用Postgres的Ecto存储一个浮点值的数组。我正在使用Ecto和Phoenix框架和Elixir。
我该如何定义我的模型和迁移?
我没有尝试太多,除了在网上搜索,没有找到任何有用的东西:-(
我确实尝试过用这样的模式定义一个模型:
schema "my_model" do
field :my_array, :array
timestamps
end
这给出了一个错误“无效或未知的类型:字段:my_array的数组”
我正在尝试用GraphQL设置一个菲尼克斯API。
我的DB中有一个Team表和一个Game表,如下所示:
schema "teams" do
field :name, :string
has_many :games, LvdnApi.Fixtures.Game
timestamps()
end
schema "games" do
field :away_team_score, :integer
field :competition, :string
field :game_datetime, :ut
我将我的代码库从Livestory重命名为Citybuilder。我对文件中的文本使用了查找和替换,然后使用mv来重命名目录。在代码库中搜索Livestory将返回零结果。
当我运行mix phx.server时,我得到:
variable "citybuilder" does not exist and is being expanded to "citybuilder()", please use parentheses to remove the ambiguity or change the variable name
mix.exs:1
我试过运行
我正在使用Phoenix Framework将Rails中编写的API重写为Elixir。
主网站使用Rails,并将继续使用Rails。但是,我希望API使用Elixir。
我需要能够从我的Elixir API项目中读取created_at字段。
defmodule Example.Recipe do
use Ecto.Schema
schema "recipes" do
field :name, :string
field :description, :string
field :slug, :string
field :creat
我最近迁移到了phoenix和ecto的最新版本。
现在我已经根据ecto changelog修改了一个模型的代码。
defmodule Spaces.Tag do
use Spaces.Web, :model
#Changed to below
defmodule Spaces.Tag do
use Ecto.Schema
我有没有给(CompileError) web/models/tag.ex:23: undefined function cast/4.买什么遗漏的东西?
我的mix.exs相关代码
defp deps do
[{:phoenix, "~>
我有postgres运行,可以连接到它,但一个全新的凤凰城应用程序通过mix phoenix.new reporting。我不能完成安装,不能做ecto.create,我能告诉你的是它没有连接到数据库...也可能是其他的虫子。从根本上说,我不知道从哪里开始。
$ psql -p 5432 -h localhost reporting_dev postgres
Password for user postgres:
psql (9.6.1, server 9.6.2)
Type "help" for help.
reporting_dev=#
这是我的config/dev.ex
在我的ecto模型中,我需要在字段中指定: user_timestamp,从unix_time转换而来的时间。移徙:
def change do
alter table(:operations) do
add :user_timestamp, :naive_datetime, null: false
end
end
我的operation.ex
schema "operations" do
field :sum, :float
field :name, :string
field :user_timestamp,
当将1的父记录的ID值传递给多个关联时,当创建子记录时,我会收到关联上的错误。
错误说我需要预加载User,它是Transaction的父记录,
1) test creates and renders resource when data is valid (MyRewardsWeb.TransactionControllerTest)
test/controllers/transaction_controller_test.exs:36
** (RuntimeError) attempting to cast or change association `us
接下来是编程菲尼克斯1.4的书。当我使用手动数据库时,这个模块工作得很好,但是当我试图切换我的accounts.ex文件时(就像这本书告诉我的那样),它坏了:
defmodule Rumbl.Accounts do
alias Rumbl.Repo
def get_user(id) do
Repo.get(User, id)
end
def get_user!(id) do
Repo.get!(User, id)
end
def get_user_by(params) do
Repo.get_by(User, params)
end
我正在尝试将argon2_elixir添加到我的菲尼克斯项目中,但编译时会出现以下错误:
mix compile
==> argon2_elixir
Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation. All rights reserved.
makefile(34) : fatal error U1000: syntax error : ')' missing in macro invocation
Stop.
co
我有两个模型,产品和图像,我想上传多个图像与产品嵌套形式使用弧包,
这是我的产品模型
defmodule FileUpload.Product do
use FileUpload.Web, :model
schema "products" do
field :name, :string
field :category, :string
has_many :images, FileUpload.Image
timestamps()
end
@doc """
Builds a changeset ba
当我使用edeliver为Elixir/Phoenix应用程序设置Ubuntu16.04服务器时,edeliver失败并返回错误消息** (Mix) The task "release" could not be found和退出代码1。如果我转到我的构建服务器,git拉出我的应用程序并在获取依赖项后运行MIX_ENV=prod mix release或mix release,我得到了相同的错误。
但是,相同的应用程序在本地运行时没有任何问题。
在服务器和本地计算机上,我的erlang版本是erts-9.0,而elixir版本是1.5.5。十六进制版本在0.16.1上也是一样的
我有团队,每个团队都有用户,所以有一个连接表将用户链接到团队,因为这是一个多对多的关系,这是我的模型:
defmodule App.Team do
use App.Web, :model
schema "teams" do
field :owner_id, :integer
has_many :team_users, {"team_user", App.TeamUser}
end
end
defmodule App.User do
use App.Web, :model
schema "users" do
我试着用String加密 .
defp encrypt_password(changeset) do
case changeset do
%Ecto.Changeset{valid?: true, changes: %{password: password}} ->
put_change(changeset, :password_hash, Fernet.Ecto.String.dump(password))
_ ->
changeset
end
end
..。在这个自动生成的测试(mix phoenix.gen.json User
我有一个has_many协会的ecto模型。默认情况下,我想用某些查询来定义这个关联。
喜欢
defmodule MyApp.User do
use MyApp.Web, :model
schema "users" do
has_many :comments, MyApp.Comment
end
end
我想获取不是deleted的注释(删除是MyApp.Comment模式的一个布尔字段,它应该等于false)。实现这一目标的途径是什么?
我的尝试#1
我试着做
has_many :comments, Ecto.Query.from(c in MyApp.
在中调用:mimemail.encode。如果它在mix phoenix.server中运行,它就能正常工作,但是它不能在发布环境(用mix release构建)中调用它。它因以下错误而崩溃:
(UndefinedFunctionError) undefined function :mimemail.encode/1 (module :mimemail is not available)
是否有任何配置可以在exrm中调用它,或者缺少要配置的东西?
application和deps在我的mix.exs中的更新如下:
def application do
[mod: {NeoSmsli