You're looking for a counter cache. I don't believe there is anything built 
in to Sequel, but I'm pretty sure you have two options off the top of my 
head.

1. Use after_add/after_remove callbacks on the `one_to_many` association, 
which count the associated `stuffs` and then update the counter cache. 

http://sequel.jeremyevans.net/rdoc/files/doc/association_basics_rdoc.html#label-3Aafter_add+-5Bone_to_many-2C+many_to_many-5D

2. Use Jeremy's sequel_postgresql_triggers gem if you're running postgres.


On Tuesday, April 18, 2017 at 6:40:01 PM UTC-4, dota? =op wrote:
>
> EHLO, 
>
> i have those Account and Stuff models. Account.one_to_many(:stuffs) 
> and i want it to have Account#stuff_count attribute so i can display 
> it on my views. And i also want it to be eager loaded, so i dont kill 
> my db. 
>
> Hints on how this can be achieved? 
>
> <3 
>
> -- 
> Igor 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to