Module: Cql::Model::PersistenceMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Cql::Model
- Defined in:
- lib/cql/model/persistence_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#delete ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/cql/model/persistence_methods.rb', line 26 def delete query = "DELETE FROM #{table_name} WHERE #{primary_key} = #{quoted_primary_value}" Cql::Base.connection.execute(query) @deleted = true @persisted = false self end |
#deleted? ⇒ Boolean
22 23 24 |
# File 'lib/cql/model/persistence_methods.rb', line 22 def deleted? @deleted end |
#save ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cql/model/persistence_methods.rb', line 4 def save updates = [] self.class.columns.each do |key, config| value = instance_variable_get("@#{config[:attribute_name].to_s}".to_sym) value = "'#{value}'" unless value.is_a?(Fixnum) updates << "#{key.to_s} = #{value}" unless value.nil? end updates = updates.join(', ') query = "UPDATE #{table_name} SET #{updates} WHERE #{primary_key} = #{quoted_primary_value}" Cql::Base.connection.execute(query) @persisted = true self end |