Hello  Javier,

I was just checking the set_table_name class method of ActiveRecord and I
think that could work for you:

class AnotherClass < ActiveRecord::Base
  has_one :worker
end

class Person < ActiveRecord::Base
  def something
    self.name
  end
end

class Worker < Person
  set_table_name "workers"
end

w = Worker.create(:name => "WorkerName")
p = Person.create(:name => "PersonName")
ac = AnotherClass.create

ac.worker = w
ac.save

ac.worker.something # => "WorkerName"

I hope that would be helpful

Daniel Gaytán

2010/9/13 Marnen Laibow-Koser <[email protected]>

> [Please quote when replying.  Otherwise the discussion is impossible to
> follow.]
>
> Javier Ruiz wrote:
> > Yep that's finally how I will have to do it... but this is not what I
> > wanted. A has_one relation means that I have to access things like:
> >
> > Anotherclass.property
> > Anotherclass.childclass.specific_property
> > Anotherclass.childclass.parentclass.common_property
>
> That makes sense from a relational point of view.  If you don't like it,
> then use STI.
>
> >
> > And more important... I need to manually manage related objects (or
> > create hooks os similar). I mean I need for example to do something
> > like:
> >
> > a = Anotherclass.new
> > b = Childclass.new
> > a.childclass = b
> >
> > ... and so on...
>
> You'd need to do that regardless of whether your original idea worked.
>
> >
> > I was thinking "rails' magic" was really magic ;-)
>
> I suppose it is, but it doesn't extend to spreading one class across
> multiple tables.
>
> If you were ambitious, you probably *could* extend ActiveRecord to do
> that, but I'm not sure it's a good idea -- it's trying to impose too
> much of an OO approach on a relational DB.  Alternatively, you could try
> an OODB like GemStone/MagLev.
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> [email protected]
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to