Created
September 25, 2013 15:04
-
-
Save fascox/6700963 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
Articolo is a Product | |
Movimento is a warehouse movement | |
Movitem is a lineitem of Movimento and refer to articles (product) | |
Question: | |
i want know the list of movement wich contain a particular article | |
if i refere to items relationship i get the error | |
class Movimento < ActiveRecord::Base | |
belongs_to :fornitore | |
belongs_to :cliente | |
has_many :items, :class_name => 'Movitem', :before_add => :check_iva | |
validates_presence_of :fornitore, :if => lambda { |m| m.causale.acquisto? } | |
validates_presence_of :cliente, :if => lambda { |m| m.causale.vendita? } | |
validates_presence_of :num_doc | |
validates_presence_of :data | |
validates_presence_of :tipo | |
validates_presence_of :causale | |
validates_presence_of :pagamento | |
validates_presence_of :stato | |
<snip> | |
end | |
class Movitem < ActiveRecord::Base | |
before_save :check_iva | |
self.table_name = 'movimenti_item' | |
after_initialize :defaults | |
attr_accessible :articolo_id, :iva, :movimento_id, :importo, :quantita, :sconto1, :sconto2 | |
belongs_to :movimento | |
belongs_to :articolo | |
validates_presence_of :articolo | |
validates_numericality_of :iva | |
validates_numericality_of :importo | |
validates_numericality_of :quantita | |
validates_numericality_of :sconto1 | |
validates_numericality_of :sconto2... | |
end | |
class Articolo < ActiveRecord::Base | |
attr_accessible :codice, :descrizione, :um | |
default_scope order('descrizione') | |
def self.search(search) | |
if search | |
where("descrizione LIKE '%#{search}%' COLLATE utf8_general_ci") | |
else | |
scoped | |
end | |
end | |
def to_s | |
descrizione | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment