> No need for send here:
>
> def part(*args, &block)
> lot.part(*args, block) # may need an if block_given?
> end
>
I was thinking that I would have to use #send since there is so much
Ruby magic wrapped inside ActiveRecord in order to map column names to
object attributes, but a very simple test
Patrick Doyle wrote:
> Wow, so now I can do:
>
> class Component < ActiveRecord::Base
> # Make component.part a shortcut for component.lot.part
> def part(*args)
> lot.send :part, args
No need for send here:
def part(*args, &block)
lot.part(*args, block) # may need an if block_given?
delegate does precisely this..checkout
http://api.rubyonrails.org/classes/Module.html#M000110
On Sep 25, 11:39 pm, Patrick Doyle wrote:
> Wow, so now I can do:
>
> class Component < ActiveRecord::Base
> # Make component.part a shortcut for component.lot.part
> def part(*args)
> lot.send
Wow, so now I can do:
class Component < ActiveRecord::Base
# Make component.part a shortcut for component.lot.part
def part(*args)
lot.send :part, args
end
end
...and do things like:
<%= mycomponent.part.number %>
...instead of ...
<%= mycomponent.lot.part.number %>
nice!
--wpd
-
On Fri, Sep 25, 2009 at 1:59 PM, Patrick Doyle wrote:
> On Fri, Sep 25, 2009 at 1:55 PM, Marnen Laibow-Koser
> wrote:
>> Part has_many :components, :through => lots
>>
>> mypart.components
>>
>> Done!
>
> Light dawns on marble head.
>
> Of course! Sorry for the noise.
oh yeah, and thanks!
--w
On Fri, Sep 25, 2009 at 1:55 PM, Marnen Laibow-Koser
wrote:
> Part has_many :components, :through => lots
>
> mypart.components
>
> Done!
Light dawns on marble head.
Of course! Sorry for the noise.
--wpd
--~--~-~--~~~---~--~~
You received this message because
Patrick Doyle wrote:
> class Part < ActiveRecord::Base
> has_many :lots
> has_many :components # or, maybe not
> end
>
> class Lot < ActiveRecord::Base
> belongs_to :part
> has_many :components
> end
>
> class Component < ActiveRecord::Base
> belongs_to :part # or, maybe not
> belong
7 matches
Mail list logo