Skip to content

Instantly share code, notes, and snippets.

@aerosol
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aerosol/8be318da01266214f242 to your computer and use it in GitHub Desktop.
Save aerosol/8be318da01266214f242 to your computer and use it in GitHub Desktop.
iex(34)> Repo.get_by(APIKey, key: "7488a646-e31f-11e4-aace-600308960662")
%Foo.APIKey{__meta__: #Ecto.Schema.Metadata<:loaded>,
account: #Ecto.Association.NotLoaded<association :account is not loaded>,
account_id: 41, id: 13, inserted_at: #Ecto.DateTime<2015-08-18T15:45:31Z>,
key: "7488a646-e31f-11e4-aace-600308960662",
updated_at: #Ecto.DateTime<2015-08-18T15:45:31Z>}
iex(35)> q = from a in Account,
...(35)> join: k in APIKey, on: a.id == k.account_id,
...(35)> where: k.key == "7488a646-e31f-11e4-aace-600308960662",
...(35)> select: {a.id, a.name}
#Ecto.Query<from a0 in Foo.Account, join: a1 in Foo.APIKey,
on: a0.id == a1.account_id,
where: a1.key == "7488a646-e31f-11e4-aace-600308960662",
select: {a0.id, a0.name}>
iex(36)> Repo.all(q)
** (Postgrex.Error) ERROR (character_not_in_repertoire): invalid byte sequence for encoding "UTF8": 0x88
(ecto) lib/ecto/adapters/sql.ex:171: Ecto.Adapters.SQL.query!/5
(ecto) lib/ecto/adapters/sql.ex:464: Ecto.Adapters.SQL.execute/6
(ecto) lib/ecto/repo/queryable.ex:95: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4
iex(36)> {:ok, uuid} = Ecto.UUID.dump("7488a646-e31f-11e4-aace-600308960662")
{:ok,
%Ecto.Query.Tagged{tag: nil, type: :uuid,
value: <<116, 136, 166, 70, 227, 31, 17, 228, 170, 206, 96, 3, 8, 150, 6, 98>>}}
iex(37)> uuid.value
<<116, 136, 166, 70, 227, 31, 17, 228, 170, 206, 96, 3, 8, 150, 6, 98>>
iex(38)> q = from a in Account,
...(38)> join: k in APIKey, on: a.id == k.account_id,
...(38)> where: k.key == <<116, 136, 166, 70, 227, 31, 17, 228, 170, 206, 96, 3, 8, 150, 6, 98>>,
(search)`sele': select: {a.id, a.name}
#Ecto.Query<from a0 in Foo.Account, join: a1 in Foo.APIKey,
on: a0.id == a1.account_id,
where: a1.key == <<116, 136, 166, 70, 227, 31, 17, 228, 170, 206, 96, 3, 8, 150, 6, 98>>,
select: {a0.id, a0.name}>
iex(39)> Repo.all(q)
** (Ecto.CastError) iex:38: value `<<116, 136, 166, 70, 227, 31, 17, 228, 170, 206, 96, 3, 8, 150, 6, 98>>` in `where` cannot be cast to type Ecto.UUID in query:
from a0 in Foo.Account,
join: a1 in Foo.APIKey,
on: a0.id == a1.account_id,
where: a1.key == <<116, 136, 166, 70, 227, 31, 17, 228, 170, 206, 96, 3, 8, 150, 6, 98>>,
select: {a0.id, a0.name}
Error when casting value to `Foo.APIKey.key`
(ecto) lib/ecto/query/planner.ex:415: Ecto.Query.Planner.normalize/3
(ecto) lib/ecto/query/planner.ex:96: Ecto.Query.Planner.query_without_cache/3
(ecto) lib/ecto/query/planner.ex:76: Ecto.Query.Planner.query/4
(ecto) lib/ecto/repo/queryable.ex:91: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment