a29e016555
Ohh ok, without this change all of our `scope`s were just immediately evaluating the argument and fetching _all_ such matching records immediately, instead of waiting to actually be called. This led to bugs like `pet_type.as_json` returning ALL pet states in the whole db, because the `PetState.emotion_order` scope was being treated as a single predefined query, rather than a query fragment to merge into the current context.
This also explains what happened in 724ed83
: that's why things before the scope in the query were being ignored.
17 lines
368 B
Ruby
17 lines
368 B
Ruby
class Species < ActiveRecord::Base
|
|
translates :name
|
|
|
|
scope :alphabetical, -> { with_translations(I18n.locale).order(Species::Translation.arel_table[:name]) }
|
|
|
|
def as_json(options={})
|
|
{:id => id, :name => human_name}
|
|
end
|
|
|
|
def human_name
|
|
if name
|
|
name.capitalize
|
|
else
|
|
I18n.translate('species.default_human_name')
|
|
end
|
|
end
|
|
end
|