{"action":"created","issue":{"url":"https://api.github.com/repos/kipcole9/money/issues/68","repository_url":"https://api.github.com/repos/kipcole9/money","labels_url":"https://api.github.com/repos/kipcole9/money/issues/68/labels{/name}","comments_url":"https://api.github.com/repos/kipcole9/money/issues/68/comments","events_url":"https://api.github.com/repos/kipcole9/money/issues/68/events","html_url":"https://github.com/kipcole9/money/issues/68","id":319174191,"number":68,"title":"Question about querying a money_with_currency column using Ecto","user":{"login":"scmx","id":603846,"avatar_url":"https://avatars2.githubusercontent.com/u/603846?v=4","gravatar_id":"","url":"https://api.github.com/users/scmx","html_url":"https://github.com/scmx","followers_url":"https://api.github.com/users/scmx/followers","following_url":"https://api.github.com/users/scmx/following{/other_user}","gists_url":"https://api.github.com/users/scmx/gists{/gist_id}","starred_url":"https://api.github.com/users/scmx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scmx/subscriptions","organizations_url":"https://api.github.com/users/scmx/orgs","repos_url":"https://api.github.com/users/scmx/repos","events_url":"https://api.github.com/users/scmx/events{/privacy}","received_events_url":"https://api.github.com/users/scmx/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-05-01T11:16:57Z","updated_at":"2018-05-01T13:45:12Z","closed_at":"2018-05-01T13:45:12Z","author_association":"NONE","body":"Hi, I'm having trouble figuring out how to query a database column with the money_with_currency  Money.Ecto.Composite.Type postgres type using Ecto.\r\n\r\n`MyApp.Repo.get_by(MyApp.Transaction, amount: Money.new(3000, :SEK))`\r\n\r\n[debug] QUERY ERROR source=\"transactions\" db=2.0ms\r\nSELECT e0.\"id\", e0.\"amount\", e0.\"inserted_at\", e0.\"updated_at\" FROM \"transactions\" AS e0 WHERE (e0.\"amount\" = $1) [{\"SEK\", #Decimal<3000>}]\r\n** (FunctionClauseError) no function clause matching in Ecto.Adapters.Postgres.TypeModule.encode_tuple/5\r\n\r\n    The following arguments were given to Ecto.Adapters.Postgres.TypeModule.encode_tuple/5:\r\n\r\n        # 1\r\n        {\"SEK\", #Decimal<3000>}\r\n\r\n<details>\r\n        # 2\r\n        1\r\n\r\n        # 3\r\n        nil\r\n\r\n        # 4\r\n        {Ecto.Adapters.Postgres.TypeModule, #Reference<0.3714461165.225312769.164420>}\r\n\r\n        # 5\r\n        []\r\n\r\n    Attempted function clauses (showing 3 out of 3):\r\n\r\n        defp encode_tuple(tuple, n, [oid | oids], [type | types], acc)\r\n        defp encode_tuple(tuple, n, [], [], acc) when tuple_size(tuple) < n\r\n        defp encode_tuple(tuple, _, [], [], _) when is_tuple(tuple)\r\n\r\n    (ecto) lib/postgrex/type_module.ex:715: Ecto.Adapters.Postgres.TypeModule.encode_tuple/5\r\n    (ecto) /myapp/deps/postgrex/lib/postgrex/type_module.ex:715: Ecto.Adapters.Postgres.TypeModule.encode_params/3\r\n    (postgrex) lib/postgrex/query.ex:45: DBConnection.Query.Postgrex.Query.encode/3\r\n    (db_connection) lib/db_connection.ex:1079: DBConnection.describe_run/5\r\n    (db_connection) lib/db_connection.ex:1150: anonymous fn/4 in DBConnection.run_meter/5\r\n    (db_connection) lib/db_connection.ex:1207: DBConnection.run_begin/3\r\n    (db_connection) lib/db_connection.ex:592: DBConnection.prepare_execute/4\r\n    (ecto) lib/ecto/adapters/postgres/connection.ex:73: Ecto.Adapters.Postgres.Connection.prepare_execute/5\r\n    (ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6\r\n    (ecto) lib/ecto/adapters/sql.ex:426: Ecto.Adapters.SQL.execute_and_cache/7\r\n    (ecto) lib/ecto/repo/queryable.ex:133: Ecto.Repo.Queryable.execute/5\r\n    (ecto) lib/ecto/repo/queryable.ex:37: Ecto.Repo.Queryable.all/4\r\n    (ecto) lib/ecto/repo/queryable.ex:70: Ecto.Repo.Queryable.one/4\r\n</details>\r\n\r\n---\r\n\r\nThen I tried this instead\r\n`import Ecto.Query; MyApp.Repo.all(from t in MyApp.Transaction, where: t.amount == ^Money.new(3000, :SEK))`\r\n`import Ecto.Query; MyApp.Repo.all(where MyApp.Transaction, [t], t.amount == ^Money.new(3000, :SEK))`\r\nthey both give the same error.\r\n\r\nI'm guessing there's just a small change in my code needed? I'd be happy to improve docs if needed.\r\n\r\nI'm wondering if could code by added to the `Money.Ecto.Composite.Type` to support passing in a money struct as is? If possible I'd guess that https://hexdocs.pm/ecto/Ecto.Type.html or https://hexdocs.pm/ecto/Ecto.Query.html should give a clue as to how."},"comment":{"url":"https://api.github.com/repos/kipcole9/money/issues/comments/385673952","html_url":"https://github.com/kipcole9/money/issues/68#issuecomment-385673952","issue_url":"https://api.github.com/repos/kipcole9/money/issues/68","id":385673952,"user":{"login":"scmx","id":603846,"avatar_url":"https://avatars2.githubusercontent.com/u/603846?v=4","gravatar_id":"","url":"https://api.github.com/users/scmx","html_url":"https://github.com/scmx","followers_url":"https://api.github.com/users/scmx/followers","following_url":"https://api.github.com/users/scmx/following{/other_user}","gists_url":"https://api.github.com/users/scmx/gists{/gist_id}","starred_url":"https://api.github.com/users/scmx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scmx/subscriptions","organizations_url":"https://api.github.com/users/scmx/orgs","repos_url":"https://api.github.com/users/scmx/repos","events_url":"https://api.github.com/users/scmx/events{/privacy}","received_events_url":"https://api.github.com/users/scmx/received_events","type":"User","site_admin":false},"created_at":"2018-05-01T13:45:12Z","updated_at":"2018-05-01T13:45:12Z","author_association":"NONE","body":"Closing since my use case is solved. Still would be great if it was possible without doing this as well"}}
{"actor":{"display_login":"scmx"}}