-
-
Save Tigraine/5356050 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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