#201 | Enhanced tenanted and untenanted associations#205
#201 | Enhanced tenanted and untenanted associations#205miguelmarcondesf wants to merge 11 commits intobasecamp:mainfrom
Conversation
|
Hi! Thanks for opening this draft. I'll dig in and review as soon as I can find time! |
|
Sorry, it's been a busy week. I will definitely get to this soon! |
There was a problem hiding this comment.
I'm not sure this is the right direction. I know in the original description I suggested something like .where(tenant_id: tenant) but that was meant to be illustrative.
The general problem that I personally need to solve is for a model where the tenant ID is not in the database.
|
Hmm. Please ignore my review for now, I'm still wrapping my head around the problem and this approach. |
flavorjones
left a comment
There was a problem hiding this comment.
This is a good start on a very complex feature. I'm not at all sure how belongs_to might be implemented, but this seems like a promising direction for the has_one and has_many side of the association.
| test "has_one automatically scopes by tenant_id" do | ||
| TenantedApplicationRecord.create_tenant("foo") do | ||
| user = User.create!(email: "user@foo.example.org") | ||
| Announcement.create!(message: "Foo announcement", tenant_id: "foo", user: user) |
There was a problem hiding this comment.
Ideally I'd like to be able to do this in an untenanted scope, but it looks like AR does some validation that requires a tenanted connection ...
I'd also like to be able to do this without explicitly setting the tenant id in Announcement, that is:
Announcement.create! user: usershould set the tenant column automatically.
There was a problem hiding this comment.
So do we want to set this tenant column automatically even for untenanted ones?
For this specific case, User is tenanted by TenantedApplicationRecord and Annoucement is using SharedApplicationRecord
I can't find a simple way to manage the ActiveRecord call to the untenanted ones unless we transform them into Subtenanted ones 🤔
@flavorjones Thanks for the awesome feedback, I'll try to get back to work here later this week! |
3895dd5 to
be86ddc
Compare
|
Hey @flavorjones |
feature: Easy associations between tenanted and untenanted models
Checklist:
has_onehas_manybelongs_to