Closed dschreij closed 10 months ago
Have you tried custom table name or scoping, mentioned in this document?
https://gorm.io/docs/conventions.html#TableName
Underlying the paginator, it will leverage gorm.Statement
to parse table name from dest model, like the code shown below:
So I'm optimistic that custom table name or scoping might be helpful.
Using TableName() works! Thank you very much :)
Gorm allows you to provide a different struct for data selection/population, if you provide the struct that specifies the table to select from in
Model()
(docs). For instance, on some occasions, I 'enrich' my model structs with composition to allow adding extra meta fields, e.g.this works in basic Gorm, where post_count will have the value specified in the select statement and the origin table is defined by
Model(User)
.I hoped the same would be possible with the
Paginate()
function, by passing theUserWithPostCount
as the destination struct, but if I try this, I get the error that the table "user_with_post_count" does not exist.Would it be possible to let the
Model()
orTable()
call specify the table to query, and not let the destination struct passed toPaginate()
define this?