I have an Organisation
resource and a Member
resource.
Each organisation is supposed to have schema based muti tenancy. So each schema will have the members table.
When I try to manage the Members in ash_admin, it gives me the option to set the tenant. But when I set the tenant and try to add a Member, it raises error - organisation: is required
I have set the writable? true
for the relationship to Organisation. Not sure what is missing to get this working.
Here is git repository which reproduces this problem: https://github.com/explorer2309/AshManyMany
Thanks!
Hmm…can I see the multi tenancy configuration of your member
resource? Is it using attribute multi tenancy?
Oh, interesting. So what is the reason to have organization_id
on the resource if the organization is defined by what tenant you’re in?
Regardless, if you’re just looking to be able to set organization_id
, you may just be looking for attribute_writable? true
on the relationship. Setting writable? true
only makes the relationship usable with manage_relationship
(which it is by default). Using attribute_writable? true
makes the underlying attribute writable (and so it would appear in the form).
Sorry, not sure if I am understanding this correctly.
The member
resource is associated with Organisation
(tenant) using this relationship
belongs_to :organisation, AshManyMany.Accounts.Organisation do
api AshManyMany.Accounts
writable? true
allow_nil? false
end
There is no other attribute for organisation_id
on the member
resource. And the writeable?
is set to true
belongs_to :organisation
creates and adds an attribute to the resource called organisation_id
. Making the relationship writable? true
(this is the default, so setting it to true
has no effect) allows you to use the manage_relationship
change, i.e:
create :create do
argument :organisation, :map
change manage_relationship(:organisation, ...options)
end
However, if you just want to be able to set the organisation_id
, then do this
belongs_to :organisation, AshManyMany.Accounts.Organisation do
api AshManyMany.Accounts
attribute_writable? true
allow_nil? false
end
That will make the organisation_id
attribute that is automatically added for the relationship writable.