Multitenancy and no_attributes? relationship option

Reading through the docs, I encountered the part about the no_attributes? option while declaring relationships.
Specifically, if you have a tenant resource like Organization , you can use no_attributes? to do things like has_many :employees, Employee, no_attributes?: true , which lets you avoid having an unnecessary organization_id field on Employee
Specifically, if you have a tenant resource like Organization , you can use no_attributes? to do things like has_many :employees, Employee, no_attributes?: true , which lets you avoid having an unnecessary organization_id field on Employee
Reading this, I was under the impression that I wouldn't have to specify a belong_to on my resource, but I encounter this error if I don't define one:
** (EXIT from #PID<0.93.0>) an exception was raised:
** (Spark.Error.DslError) [Vigil.Fleet.Plane]
multitenancy -> attribute:
Attribute airline_id used in multitenancy configuration does not exist
** (EXIT from #PID<0.93.0>) an exception was raised:
** (Spark.Error.DslError) [Vigil.Fleet.Plane]
multitenancy -> attribute:
Attribute airline_id used in multitenancy configuration does not exist
Am I missing something or do I still need to define a belong_to for my Plane resource? For reference, my airline resource has the following:
has_many :planes, Vigil.Fleet.Plane do
api Vigil.Fleet
no_attributes? true
end
has_many :planes, Vigil.Fleet.Plane do
api Vigil.Fleet
no_attributes? true
end
5 Replies
ZachDaniel
ZachDaniel3y ago
Well, if you want to use attribute multitenancy you will still need an attribute to exist to store the tenant in In the case of attribute multitenancy there isn’t much point to using the no_attributes? option although you technically can. But you’d need to do something like add attribute :organization_id, … at a minimum.
richaard0
richaard0OP3y ago
Oh right, I guess the example would be if I was using a :context strategy to implement multitenancy?
ZachDaniel
ZachDaniel3y ago
Yeah, exactly
richaard0
richaard0OP3y ago
I totally forgot about that other option, that explains it, thanks! (quite the response time there 😄 )
ZachDaniel
ZachDaniel3y ago
Gotta go fast 😂

Did you find this page helpful?