Hi all !

------------------------------------------------------------------------
r3679 | bitsweat | 2006-02-26 19:27:48 -0500 | 1 line

Define attribute query methods to avoid method_missing calls. Closes #3677.
------------------------------------------------------------------------

Unfortunately, that changeset causes problems with my code...

I have a table named estimate_lines, with the following columns:
id
position
estimate_id
product_id
quantity
unit_price
comment
line_type

r3679 now always defines reader, writer and reader? methods.  My model
looks like this:
class EstimateLine < ActiveRecord::Base
  belongs_to :estimate
  belongs_to :product

  def comment?()
    line_type == 'comment'
  end

  # other methods removed
end

What happens is that my #comment? method is overriden by ActiveRecord.
 That's BAD.  Of course, my method is just a shortcut for the query,
and it could probably be replaced with an STI, but you know, I was
young back then...

On the other hand,  my quote objects have a #paid_in_full? method as
well as a column with the same name.  The implementation checks some
things before replying, but is a side-effect free operation.  The
column is there as a cache of the value, which I update through other
means.

I would propose to update this changeset to implement the method, only
if it is currently undefined.  Same goes for reader and writer
methods, I would guess.  Haven't tested, but does this changeset
overwrite custom attribute getters/setters ?

Bye !
--
François Beausoleil
http://blog.teksol.info/
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to