yup, sebelumnya saya pakai acts_as_tree tapi sekarang saya menggunakan STI, 
rasanya bener aja :p

class Location < ActiveRecord::Base
end

class Branch < Location
    has_many :regions, :foreign_key => :parent_id # parent_id sebelumnya 
dipakai buat acts_as_tree
end

class Region < Location
    belongs_to :branch, :foreign_key => :parent_id
    has_many :streets, :foreign_key => :parent_id
end

class Street < Location
    belongs_to :region, :foreign_key => :parent_id
    has_many :customers
end

cheers...


(\ /)
(O.o)
(> <)

This is Bunny. Copy Bunny into your signature to help him on his way to 
world domination.




________________________________
From: Reza Primardiansyah <[email protected]>
To: [email protected]
Sent: Fri, November 13, 2009 3:54:12 PM
Subject: Re: [id-ruby] acts as tree atau STI ?

Pertanyaan utamanya lebih pada "apakah memang bisa dikelompokkan jadi satu
entitas besar (superclass)? Apa nama superclass itu?"

Saya sendiri membuat perjenjangan wilayah administratif (Propinsi,
Kabupaten, dst) pakai STI *dan* acts_as_tree (sedang nimbang2 pakai
ancestry).

class Location < AR::Base
  acts_as_tree
end

class Propinsi < Location
  has_many :kabupaten2  #mbuat aturan pluralisasi sendiri di
config/environment.rb
end

class Kabupaten < Location
  belongs_to :propinsi
end

Hope this helps

2009/11/12 rahmat budiharso <[email protected]>

>
>
> saya punya format data seperti ini:
>
> branch has many regions
>
> region belongs to branch
> region has many streets
>
> street belongs to region
> street has many customers
>
> atribut untuk branch, region n street sama (hanya code n name), nah
> kira-kira lebih baik pakai plugin acts_as_tree atau single table inheritance
> ?
>
> makasih...
>
> (\ /)
> (O.o)
> (> <)
>
> This is Bunny. Copy Bunny into your signature to help him on his way to
> world domination.
>
> [Non-text portions of this message have been removed]
>
>  
>


[Non-text portions of this message have been removed]



------------------------------------

ID-Ruby
Berdiskusi dan belajar bersama Bahasa Pemrograman Ruby, termasuk segala varian 
Ruby (JRuby, Rubinius, IronRuby, XRuby), dan program yang dibuat dengan Ruby 
(Ruby on Rails, JRuby on Rails, Merb)

    http://rubyurl.com/Q8DD
    http://news.gmane.org/gmane.comp.lang.ruby.region.indonesia





      

[Non-text portions of this message have been removed]

Kirim email ke