Class: Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Asset
- Defined in:
- app/models/asset.rb
Class Method Summary collapse
-
.count_for_labels(filter) ⇒ Object
FIXME: is this used somewhere? should be removed right after the release of 0.3.0 to test if something breaks.
- .filter(filter) ⇒ Object
Instance Method Summary collapse
Class Method Details
.count_for_labels(filter) ⇒ Object
FIXME: is this used somewhere? should be removed right after the release of 0.3.0 to test if something breaks
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/asset.rb', line 24 def self.count_for_labels(filter) = {:include => [:labelings], :group => "label_id"} unless filter.empty? [:conditions] = "assets.id IN( SELECT DISTINCT assets.id FROM assets LEFT OUTER JOIN classifications ON (assets.id = classifications.asset_id) LEFT OUTER JOIN labelings ON (labelings.classification_id=classifications.id) WHERE (#{filter.to_condition}) GROUP BY assets.id HAVING COUNT(label_id)=#{filter.size})" filter.to_condition end count end |
.filter(filter) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/models/asset.rb', line 13 def self.filter(filter) = {:select => "assets.*", :order => "name"} unless filter.empty? [:joins] = "LEFT OUTER JOIN labelings ON labelings.classification_id=classifications.id" [:conditions] = filter.to_condition [:group] = "assets.id HAVING COUNT(label_id)=#{filter.size}" end all end |
Instance Method Details
#put_on_tray ⇒ Object
40 41 42 43 44 45 |
# File 'app/models/asset.rb', line 40 def put_on_tray return if user.nil? p = user.tray_positions.maximum(:position) || 0 tray_positions.create(:user_id => user.id, :asset_id => id, :position => p + 1) end |