Created
May 22, 2014 20:38
-
-
Save luizkowalski/880cc9e2e4fb7da8b918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The classes | |
class ReducaoZ < ActiveRecord::Base | |
self.table_name = 'reducaoz' | |
belongs_to :empresa | |
belongs_to :impressorafiscal, foreign_key: 'impressorafiscal_id', class_name: 'ImpressoraFiscal' | |
belongs_to :usuario_cadastro, foreign_key: 'usuariocadastro_id', class_name: 'Usuario' | |
belongs_to :usuario_alteracao, foreign_key: 'usuarioalteracao_id', class_name: 'Usuario' | |
has_many :aliquotas, primary_key: 'id', foreign_key: 'reducaoz_id', class_name: 'Aliquota', dependent: :delete_all | |
end | |
class Aliquota < ActiveRecord::Base | |
self.table_name = 'aliquota' | |
belongs_to :reducaoz, class_name: 'ReducaoZ', primary_key: 'reducaoz_id', foreign_key: 'id' | |
end | |
# The method | |
json_data.aliquotas_list.each_with_index do |al, index| | |
aliquota = reducao.aliquotas.build | |
# populate aliquota | |
red.aliquotas << aliquota | |
end | |
red.save! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment