Is there a way to use an existing schema for creating relationships in an Ash Resource

Hi

I have an existing ecto schema say “Organization”.
Now I have Ash.Resource say Branch
Is there a way to create relationship like

relaltionships belongs_to :org, Organization end
A way to wrap an existing schema and use it as a Ash.Resource. Please guide.
BTW loving the way Ash is progressing. I am betting my new venture on Ash.

-Srikanth

1 Like

There is not a way to do this unfortunately. You’ll need to make an Organization resource if you want to use relationships with it.

1 Like

@zachdaniel The resource can be an existing table managed by another schema as well right? I don’t see Ash restricting that. In this case, Organization can be both a plain Ecto Schema as well as an Ash Resource?

I use mix phx.gen.auth for generating my auth schemas and liveview endpoints. I haven’t switched to use Ash Authentication yet. However, I still need to refer to the User records in my Ash Resources. So I created a resource file for the existing User schema with only email field (I don’t want the password fields exposed on my Ash Resoruce) and it works fine. Not sure, if this has any drawbacks. It would be good to know from you.

2 Likes

Correct, no issues there.

Add

postgres do
  migrate? false
end

To skip Generating migrations for it

2 Likes

Good heavens, I should spend more time reading the Ash docs. It is truly pragmatic.

2 Likes
postgres do
    table "orgs"
    migrate? false

    manage_tenant do
      template ["org_", :id]
    end
  end

Will ash still be able to handle the schema creation/migrations for multitenancy if migrate? false?

It should, yes. It will run the migrations that are in the configured tenant migrations folder which defaults to IIRC priv/repo/tenant_migrations, regardless of if it was responsible for generating them.