How to map one-to-one relation to two tables

hi. iv got a problem with one-to-one relation with AR. let’s say I need
this classes:

class ContentObject < ActiveRecord::Base
class BlogEntry < ContentObject
class FotoEntry < ContentObject

i.e. Blog and Foto entries must extend ContentObject. Also they must be
mapped to separate tables. I can not figure out how to map this kind of
association better?

The most dumb and straitforward way is actually NOT to extend
ContentObject and associate it as regular has-one and belongs-to, but
that way all beauty will b gone, since i’ll need manually treat object
instantiation etc., maybe there are much more elegant ways to solve this
kind of problems?

rest less wrote:

hi. iv got a problem with one-to-one relation with AR. let’s say I need
this classes:

class ContentObject < ActiveRecord::Base
class BlogEntry < ContentObject
class FotoEntry < ContentObject
i.e. Blog and Foto entries must extend ContentObject. Also they must be
mapped to separate tables. I can not figure out how to map this kind of
association better?

How about:

module ContentBehaviour
#whatever behaviour is shared
end

class BlogEntry < ActiveRecord::Base
include ContentBehaviour
end

class FotoEntry < ActiveRecord::Base
include ContentBehaviour
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs