livehelpnow / tds_ecto

TDS Adapter for Ecto
57 stars 34 forks source link

How use Schemas of msSQL ? #41

Closed nerus closed 7 years ago

nerus commented 7 years ago

I have a model like this defmodule AppRest.Category do use AppRest.Web , :model schema "ventas.categories" do field :name, :string timestamps() end when i use it in the controller, with Repo.all def index(conn, _params) do categories = Repo.all(Category) render(conn, "index.json", categories: categories) end it generate the query like this SELECT g0.[id], g0.[name], g0.[inserted_at], g0.[updated_at] FROM [global.categories] AS g0 then MSSQL can't process the query and return this error: "The object name 'Ventas.categories' is not valid." The query in right format is like this SELECT g0.[id], g0.[name], g0.[inserted_at], g0.[updated_at] FROM [global].[categories] AS g0

So the question is how i can set the name of schema of the table of MSSQL, in the model?

I hope any can help me with this.

hectorsq commented 7 years ago

Which version of Ecto are you using? Remember that tds_ecto does not work yet with Ecto 2 #34

nerus commented 7 years ago

This config is in mix.exs file

def application do [mod: {AppRest, []}, applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext, :phoenix_ecto, :tds_ecto]] end

defp deps do [{:phoenix, "~> 1.2.1"}, {:phoenix_pubsub, "~> 1.0"}, {:phoenix_ecto, "~> 2.0"}, {:phoenix_html, "~> 2.6"}, {:phoenix_live_reload, "~> 1.0", only: :dev}, {:gettext, "~> 0.11"}, {:cowboy, "~> 1.0"}, {:tds_ecto, "~> 1.0.2"}] end

hectorsq commented 7 years ago

Could you post your mix.lock file?

nerus commented 7 years ago

here is mix.txt

nerus commented 7 years ago

the mix.lock file mix_lock.txt

andrei-mihaila commented 7 years ago

I had a similar problem. The workaround I found was (kind of ugly): :model schema "schema].[table" - this should generate a SELECT ... FROM [schema].[table] ....

mjaric commented 7 years ago

It is supported now in ecto2 branch. It is still WIP. It works the same way as it was done in psotgresql adapter

mjaric commented 7 years ago

This is now supported in latest master branch which is supporting ecto up to version 2.1.X. You have to use @prefix "schema" above schema macro.