[Rails] Re: How to ensure two tables reference the same record in a

2009-09-28 Thread Patrick Doyle
> 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

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-28 Thread Marnen Laibow-Koser
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?

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-27 Thread Subbu
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

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-25 Thread Patrick Doyle
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 -

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-25 Thread Patrick Doyle
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

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-25 Thread Patrick Doyle
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

[Rails] Re: How to ensure two tables reference the same record in a

2009-09-25 Thread Marnen Laibow-Koser
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