ankane / blazer

Business intelligence made simple
MIT License
4.5k stars 471 forks source link

generating a variable based on request.host #467

Closed dvodvo closed 7 months ago

dvodvo commented 7 months ago

Tag: question(s) Context: multitenant application Goal: offer queries based on active tenant_id

Thus a use of smart variables could work for the query as such

smart_variables:
  tenant_id: "SELECT id, name FROM tenants ORDER BY name ASC"
[...]
SELECT * FROM posts WHERE tenant_id = {tenant_id}

my understanding of the example of time ranges is that blazer will create a pulldown menu with the name values of tenants table.
Q1 - is this understanding correct? But that is not desired; a hard-wiring of the value is necessary.

note users can have multiple tenancies; the active tenant_id is derived from a tenant_user table

The rails application gets a clean_host from an application controller method - which would be the same used within the gem's routing choice:

    rurl = request.host  
    clean_host = rurl.chomp("/")
    @tenant_id = Site.where('host = ?', clean_host.to_s).first.tenant_id

Q2 - how can the derived tenant_id be handled in the query?

ankane commented 7 months ago

Hi @dvodvo, Blazer isn't designed for this use case, so you'd need to fork it to do this.

dvodvo commented 7 months ago

It makes sense, upon reflection, that Blazer not handle this outright. For tenant-based analysis a controller action could easily access the data Ahoy saved, while chartkick could render graphical representations.