Skip to content

Conversation

@gmhawash
Copy link

@gmhawash gmhawash commented Dec 2, 2024

Our use case allows for models to be namespaced as we're taking advantage of Rails Multi-Database access. As a result, each database models are namespaced; e.g., DB1::Tenant. We also want to be able to use the parent or scope option when we access sub-associations. e.g., DB1::Tenant.has_many :certificates, hence:

expose :tenant, model_namespace: :DB1
expose :certificate, parent: :tenant, model_namespace: :DB1

This translates to:

def tenant = DB1::Tenant.find_or_initialize_by(id: params[:id])
def certificate = tenant.certificates.find_or_initialize_by(id: params[:id])

@mattpolito
Copy link
Member

@gmhawash Thanks so much for the PR!

Before I look into this, have you tried using the model option?

It should work out like this:

expose :certificate, parent: :tenant, model: DB1::Certificate

@gmhawash
Copy link
Author

gmhawash commented Dec 4, 2024

@mattpolito the code prevents parent and model to be used at the same time.

@mattpolito
Copy link
Member

I'd like to remedy the 'incompatible option' situation over adding and additional option for name-spacing. Let me look into that.

@gmhawash
Copy link
Author

gmhawash commented Dec 4, 2024

I would be happy to try it if you do it soonish. Thanks

@mattpolito
Copy link
Member

I'm planning to take a look at it toward the end of the month around the holidays

@gmhawash
Copy link
Author

gmhawash commented Dec 5, 2024 via email

@gmhawash
Copy link
Author

@mattpolito Hi Matt, did you get a chance to take a look at this issue?

@mattpolito
Copy link
Member

@gmhawash I did not, was sick my entire vacation when I was going to look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants