You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am thinking of putting extra condition of tenant_id at this. I am thinking of using where_tenant() method that adds this extra condition in User.where.
Could some help me in how can I write where_tenant() method ?
use Amnesia
defdatabase Test.Database do
deftable Message, [:user_id, :content], type: :bag do
def user(self) do
User.read(self.user_id)
end
def user!(self) do
User.read!(self.user_id)
end
end
deftable User, [{ :id, autoincrement }, :name, :email], type: :ordered_set, index: [:email] do
end
end
defmodule DatabaseTest do
use ExUnit.Case
use Test.Database
alias Amnesia.Selection
alias Amnesia.Table.Stream
test "where works" do
Amnesia.transaction! do
%User{id: 1, name: "John"} |> User.write
%User{id: 2, name: "Lucas"} |> User.write
%User{id: 3, name: "David"} |> User.write
end
assert(Amnesia.transaction! do
assert Selection.values(User.where_tenant(name == "John", select: id)) == [1]
assert Message.where_tenant(name == "Richard") == nil
end
end
end
The text was updated successfully, but these errors were encountered:
I am new to Elixir and we inhertited a project build on Amnesia. In order to make this multitenant, I am planning to override table definition methods like "where"
https://github.com/meh/amnesia/blob/master/lib/amnesia/table/definition.ex?#L11
I am thinking of putting extra condition of tenant_id at this. I am thinking of using where_tenant() method that adds this extra condition in User.where.
Could some help me in how can I write where_tenant() method ?
use Amnesia
defdatabase Test.Database do
deftable Message, [:user_id, :content], type: :bag do
def user(self) do
User.read(self.user_id)
end
end
deftable User, [{ :id, autoincrement }, :name, :email], type: :ordered_set, index: [:email] do
end
end
defmodule DatabaseTest do
use ExUnit.Case
use Test.Database
alias Amnesia.Selection
alias Amnesia.Table.Stream
test "where works" do
Amnesia.transaction! do
%User{id: 1, name: "John"} |> User.write
%User{id: 2, name: "Lucas"} |> User.write
%User{id: 3, name: "David"} |> User.write
end
end
end
The text was updated successfully, but these errors were encountered: