ronindev
How to handle many to many relationships between diferent apis?
Hello I am trying to do a many to many association between resources from two diferent apis this is my registry from both sides
defmodule Hatamoto.Accounts.Registry do
alias Hatamoto.Accounts.{Client, ClientBranch, Company, Employee, Subscription, Token}
use Ash.Registry
entries do
entry Client
entry ClientBranch
entry Company
entry Employee
entry Subscription
entry Token
end
end
defmodule Hatamoto.Engine.Registry do
alias Hatamoto.Engine.{
Bill,
Branch,
Delivery,
Discount,
Notification,
Product,
Reminder,
Sale,
Stock,
Vehicle
}
use Ash.Registry
entries do
entry Bill
entry Branch
entry Delivery
entry Discount
entry Notification
entry Product
entry Reminder
entry Sale
entry Stock
entry Vehicle
end
end
This is my relationship on client module
many_to_many :branches, Hatamoto.Engine.Branch do
api Hatamoto.Engine
through Hatamoto.Accounts.ClientBranch
source_attribute_on_join_resource :client_id
destination_attribute_on_join_resource :branch_id
end
this is my relationship from branch
many_to_many :clients, Hatamoto.Accounts.Client do
api Hatamoto.Accounts
through Hatamoto.Accounts.ClientBranch
source_attribute_on_join_resource :branch_id
destination_attribute_on_join_resource :client_id
end
and this is my relationship from clientBranch resouse
relationships do
belongs_to :client, Hatamoto.Accounts.Client do
primary_key? true
allow_nil? false
end
belongs_to :branch, Hatamoto.Engine.Branch do
primary_key? true
allow_nil? false
end
end
But i got this error
Resource `Hatamoto.Accounts.ClientBranch` is not accepted by api `Hatamoto.Engine` for autogenerated join relationship: `:branches_join_assoc`
Relationship was generated by the `many_to_many` relationship `:branches`
If the `through` resource `Hatamoto.Accounts.ClientBranch` is not accepted by the same
api as the destination resource `Hatamoto.Engine.Branch`,
then you must define that relationship manually. To define it manually, add the following to your
relationships:
has_many :branches_join_assoc, Hatamoto.Accounts.ClientBranch do
# configure the relationship attributes
...
end
You can use a name other than `:branches_join_assoc`, but if you do, make sure to
add that to `:branches`, i.e
many_to_many :branches_join_assoc, Hatamoto.Accounts.ClientBranch do
...
join_relationship_name :your_new_name
end
First Post!
zachdaniel
Creator of Ash
Thanks for the question
Responded on the GH issue: How I can handle a many to many relationship between two diferent apis? · ash-project/ash · Discussion #872 · GitHub
Popular in Questions
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
I am trying to implement my new.html.eex file to create new posts on my website.
new.html.eex:
<h1>Create Post</h1>
<%= ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)?
Would
mix ecto.rollback -v 200809061...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Other popular topics
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









