| Class | Field |
| In: |
app/models/field.rb
|
| Parent: | Object |
| attributes | [RW] | |
| database | [RW] | |
| table | [RW] |
This method assigns the database and table this field appears in, along with all the attributes, no matter how useless they may be.
# File app/models/field.rb, line 14
14: def initialize( table, attributes )
15: self.table = table
16: self.attributes = attributes
17: self.database = self.table.database
18: end
This is our obligation to Comparable. Order by column id (which is faked for some databases).
# File app/models/field.rb, line 24
24: def <=>( other )
25: self.cid <=> other.cid
26: end
inconsistant on some databases
# File app/models/field.rb, line 99
99: def primary
100: self.attributes[:primary]
101: end
not all databases send this
# File app/models/field.rb, line 64
64: def sql_type
65: self.attributes[:sql_type]
66: end
Update the field using the parameters passed. This first checks the name for an update then operates on the actual field attributes.
# File app/models/field.rb, line 33
33: def update( params )
34: switch( self.database ) do
35: if params['field'] != params['fields']['1']['name']
36: ActiveRecord::Base.connection.rename_column( self.table.name.to_sym,
37: params['field'].to_sym,
38: params['fields']['1']['name'].to_sym )
39: end
40: ActiveRecord::Base.connection.change_column( self.table.name.to_sym,
41: params['fields']['1']['name'].to_sym,
42: params['fields']['1']['type'].to_sym,
43: mangle_column_options( params, '1' ) )
44: end
45: end