How to build WHERE IN array clause with Ecto?
The following should work: posts = Post |> where([p], p.id in [1, 2]) |> Repo.all
The following should work: posts = Post |> where([p], p.id in [1, 2]) |> Repo.all
From the documentation: Changesets allow filtering, casting, validation and definition of constraints when manipulating models.. There is an example of working with changesets in the introductory documentation in the Ecto module. The functions change/2 and cast/4 are the usual entry points for creating changesets, while the remaining functions are useful for manipulating them. Changesets are … Read more
Is it an abstraction layer between the two Yes, exactly! Plug is meant to be a generic adapter for different web servers. Currently we support just Cowboy but there is work to support others. Plug also defines how different components should be plugged together. Similar to Rack in Ruby, WSGI in Python, Ring in Clojure, … Read more
Update to Poison 1.5. With it you can declare in your models: @derive {Poison.Encoder, only: [:foo, :bar, :baz]} schema “your schema” do field :foo field :bar field :baz end It is going to be faster, safer and cleaner.
Please see the fix here: https://github.com/phoenixframework/phoenix/issues/1410 Upgrade to node >= v5.0.0 npm cache clean cd my_app rm -rf node_modules/ npm install mix phoenix.server
As you’ve already mentioned, Access‘s implementation was changed to use Behaviours instead of Protocols. The reasoning was performance. Protocols are type/data based polymorphism, and are exclusive to Elixir. That means it lets you dispatch based on the data structure Behaviours are a typeless mechanism that don’t rely on a data structure, but the module as … Read more
You want to use unique_constraint/3. This is not like Active Record because it is using the database to ensure uniqueness. Active Record would do a query for records with the same value and if any were returned then it would fail. This has a race condition where, if a value is inserted between fetching to … Read more
It’s not documented on that page, but it’s documented in Kernel.=~/2 that when the RHS is a string, =~ checks if LHS contains RHS: iex(1)> “foo” =~ “f” true iex(2)> “foo” =~ “o” true It does not implicitly convert RHS to regex: iex(3)> “foo” =~ “.” false If RHS is a regular expression, returns true … Read more
It specifies a default value. Function arguments defined using \\ after the argument name are providing an optional default. So if loop/2 is called, the first argument will be the pid returned from self(). If loop/3 is called, then you would specify a pid. Let’s take another (trivial) example: math.ex defmodule Math do def add(a … Read more
Since 0.10.3 you need to put the partial application between parentheses preceded by the & operator. You won’t have any trouble with this version: iex> square = &(&1 * &1) iex> square.(5) 25 iex> cube = &(&1 * &1 * &1) iex> cube.(5) 125