102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/urbix/acts_as_view.rb', line 102
def acts_as_view(options = {})
Logger.debug "ActsAsView on #{self}"
vr = ViewRelations.new(self)
yield vr if block_given?
sc = self.columns_hash.keys.collect{|col| "#{self.table_name}.#{col}"}
sc << vr.select_clause unless vr.select_clause.empty?
fc = vr.from_clause
wc = vr.join_clause
self.class_variable_set(:@@_View__Relations,[sc,fc,wc])
class_eval do
def self.view
sc,fc,wc = self.class_variable_get(:@@_View__Relations)
select(sc).from(fc).where(wc)
end
end
end
|