Hello!
I am trying to filter the information displayed on one of my pages, so I’m using:
info := usersTable.GetInfo().Where(...)
In this Users table I want to display the email from another table, so I do a JOIN with FieldJoin
:
info.AddField(lang.Translate("primary_email"), "address", db.Varchar).
FieldJoin(types.Join{
Table: "emails",
Field: "id",
JoinField: "user_id",
})
I want to limit these emails, so I want to add a condition on column is_secondary
of emails
table. Here is the code:
info := usersTable.GetInfo().
SetTable("users").
SetTitle(lang.Translate("users")).
SetDescription(lang.Translate("users")).
Where("users.tenant_id", "=", tenantID).
Where("emails.is_secondary", "=", false)
is_secondary
is stored in the Database as a Boolean. I don’t know why, but this causes an error in the SQL generated by Go Admin. Specifically, this code Where("emails.is_secondary", "=", "false")
seems to be breaking the SQL generator, because I get:
select \"users\".\"employment_status_id\", ... where users.\"tenant_id\" = $1 and GROUP BY \"users\".\"id\" order by ...
As you can see, there is an empty and
before GROUP, that breaks the query.
None of these work:
Where("emails.is_secondary", "=", "'false'")
Where("emails.is_secondary", "=", "false")
Where("emails.is_secondary", "=", `"false"`)
Where("emails.is_secondary", "=", false)
this is what I ended up using:
WhereRaw(`emails.is_secondary = 'false'`)
But this method has to be applied to the entire info object, it affects all the rows, so those people where is_secondary=true
, that I want to show, will not appear in the page
Any idea why those Where()
methods were not working?