def cast_association(k)
      if self.class.one2many_associations[k]
        if @loaded_associations[k]
          v = @loaded_associations[k].select {|i| i.changed?}
          v = @associations[k] if v.empty?
        else
          v = @associations[k]
        end
        cast_o2m_association(v)
      elsif self.class.many2many_associations[k]
        v = @associations[k]
        [[6, false, (v || []).map {|i| i.is_a?(Base) ? i.id : i}]]
      elsif self.class.many2one_associations[k]
        v = @associations[k] # TODO support for nested
        cast_m2o_association(v)
      end
    end
def cast_association(k)
      if self.class.one2many_associations[k]
        if @loaded_associations[k]
          v = @loaded_associations[k].select {|i| i.changed?}
          v = @associations[k] if v.empty?
        else
          v = @associations[k]
        end
        cast_o2m_association(v)
      elsif self.class.many2many_associations[k]
        v = @associations[k]
        [[6, false, (v || []).map {|i| i.is_a?(Base) ? i.id : i}]]
      elsif self.class.many2one_associations[k]
        v = @associations[k] # TODO support for nested
        cast_m2o_association(v)
      end
    end
talk OpenERP cryptic associations API