I'm trying to implement pagination, and for UX (pagination links) I need to know the total count of tuples inside the paginated relation. The current API for Relation#summarize, and adding a :count column specifically, forces me to know an existing attribute name present in the relation. Ideally, that wouldn't be necessary tho, because it leaves the burden of knowing relation internals to the callsite (in order to paginate, I need to know one (arbitrary?) NOT NULL attribute).
I'm currently pondering, whether I should simply accept having to know one attribute name (thus including it as a param in the API for pagination) or whether I should do something "clever" to get at one arbitrary name. Something like the following (which imo really is ugly):
def count
relation.summarize { |r|
r.add(:count, r.send(relation.header.keys.to_a[0].to_a[0].name).count)
}.sort.one[:count]
end
Both options seem less than ideal to me. It seems like what i really want, is COUNT (*), but nowhere in axiom-sql-generator specs can I find examples of axiom actually being able to produce that.
Any pointers would be very much appreciated! Thx in advance!
I'm trying to implement pagination, and for UX (pagination links) I need to know the total count of tuples inside the paginated relation. The current API for
Relation#summarize, and adding a:countcolumn specifically, forces me to know an existing attribute name present in the relation. Ideally, that wouldn't be necessary tho, because it leaves the burden of knowing relation internals to the callsite (in order to paginate, I need to know one (arbitrary?)NOT NULLattribute).I'm currently pondering, whether I should simply accept having to know one attribute name (thus including it as a param in the API for pagination) or whether I should do something "clever" to get at one arbitrary name. Something like the following (which imo really is ugly):
Both options seem less than ideal to me. It seems like what i really want, is
COUNT (*), but nowhere inaxiom-sql-generatorspecs can I find examples of axiom actually being able to produce that.Any pointers would be very much appreciated! Thx in advance!