Module: Forcast::Model::Asociar
Instance Method Summary collapse
- #agregar_asociado(modelo, id) ⇒ Object
- #agregar_asociado_a?(modelo, id) ⇒ Boolean
- #asociado_a?(modelo, id) ⇒ Boolean
- #asociado_existe?(modelo, id) ⇒ Boolean
- #asociar_a(modelo, id) ⇒ Object
- #c_to_m(str) ⇒ Object
- #desasociar_de(modelo) ⇒ Object
- #quitar_asociado(modelo, id) ⇒ Object
- #ver_asociado(modelo) ⇒ Object
Instance Method Details
#agregar_asociado(modelo, id) ⇒ Object
31 32 33 34 |
# File 'lib/forcast/models/asociar.rb', line 31 def agregar_asociado(modelo,id) nombre = (self.class.name + '_id').downcase c_to_m(modelo).find(id).update( nombre => self.id) end |
#agregar_asociado_a?(modelo, id) ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/forcast/models/asociar.rb', line 54 def agregar_asociado_a?(modelo, id) nombre = (self.class.name + '_id').downcase c_to_m(modelo).find(id).read_attribute(nombre) === self.id.to_i ? false : true end |
#asociado_a?(modelo, id) ⇒ Boolean
48 49 50 51 52 |
# File 'lib/forcast/models/asociar.rb', line 48 def asociado_a?(modelo, id) self.read_attribute(modelo) === id.to_i ? false : true end |
#asociado_existe?(modelo, id) ⇒ Boolean
61 62 63 64 65 |
# File 'lib/forcast/models/asociar.rb', line 61 def asociado_existe?(modelo, id) c_to_m(modelo).exists?(id) ? true : false end |
#asociar_a(modelo, id) ⇒ Object
25 26 27 28 29 |
# File 'lib/forcast/models/asociar.rb', line 25 def asociar_a(modelo, id) self.update(modelo => id) end |
#c_to_m(str) ⇒ Object
67 68 69 |
# File 'lib/forcast/models/asociar.rb', line 67 def c_to_m(str) return str.classify.constantize end |
#desasociar_de(modelo) ⇒ Object
36 37 38 39 40 |
# File 'lib/forcast/models/asociar.rb', line 36 def desasociar_de(modelo) self.update(modelo => 1) end |
#quitar_asociado(modelo, id) ⇒ Object
42 43 44 45 |
# File 'lib/forcast/models/asociar.rb', line 42 def quitar_asociado(modelo,id) nombre = (self.class.name + '_id').downcase c_to_m(modelo).find(id).update( nombre => 1) end |
#ver_asociado(modelo) ⇒ Object
19 20 21 22 23 |
# File 'lib/forcast/models/asociar.rb', line 19 def ver_asociado(modelo) return c_to_m(modelo).where(:id => self.id) end |