Skip to content

Instantly share code, notes, and snippets.

@Tigraine
Forked from ansix/gist:5356037
Last active December 16, 2015 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tigraine/5356050 to your computer and use it in GitHub Desktop.
Save Tigraine/5356050 to your computer and use it in GitHub Desktop.
class Festival < ActiveRecord::Base
attr_accessible :name, :client_id
belongs_to :client
has_many :covers
has_many :photos
def self.with_covers
where("covers_count > 0") # or some other SQL with a COUNT and group maybe that filters correctly
end
def as_json(opts = {})
if !covers.empty?
opts = opts.merge({
:except => [:created_at, :updated_at],
:include => {
:covers => {
:methods => [:image_url, :thumbnail_url],
:except => [:created_at, #:updated_at,
:main_text_block_id, :left_text_bar_id,
:first_left_text_block_id, :second_left_text_block_id, :third_left_text_block_id,
:first_right_text_block_id]
}
}
})
super(opts)
end
end
end
render json: @festivals.with_covers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment