I have a many-to-many relationship through a join table. This join table has an additional field, an integer.
Now for filtering purposes, I want to add an attribute to one of the models reflecting the sum of this additional field for the associated entries.
I’ve tried stuff like:
has "SUM(<join_table_name.field_name>)", :as => :availability, :type => :int
But this just yields errors like “nil is not a symbol” when running rake ts:rebuild. I assume I’m just doing it wrong, so before I add a lot of unnecessary additional info, I thought I’d see if someone knows the correct way to do this?
I think you’re almost there – but first, it’s
:integer, not:int– and secondly, if the join is not being referred to normally by any other fields or attributes, then you need to ensure it’s part of the query:Beyond that, it’s all looking fine.