Create relationship with itself

How can we add a relationship from some resource to itself? For example, let's say I have a User resource and I add a feature that an user can create another user, meaning that I want to add a field called created_by and created_by_id which is also an User
4 Replies
ZachDaniel
ZachDaniel3y ago
yep!
Blibs
BlibsOP3y ago
Hmm, yep what? hahahaha. Basically I tried adding a has_one or belongs_to blocks using the resource module itself but they will fail when creating the migration with ** (RuntimeError) Error while running transformer AshPostgres.Transformers.EnsureTableOrPolymorphic: "Non-polymorphic resources must have a postgres table configured."
ZachDaniel
ZachDaniel3y ago
You can relate a resource to itself that error implies you haven't configured a table for a resource like
postgres do
table "table" # <- you haven't done this somewhere
end
postgres do
table "table" # <- you haven't done this somewhere
end
Blibs
BlibsOP3y ago
Hmm, I guess there was some problem with an alias to the resource, because the issue was that it was not finding the resource 🤦‍♂️

Did you find this page helpful?