I search an plugin or gem, but don''t find nothing satisfactory. I believe to be stranger a technology that nails the DRY, have that create you vary equal tables, instead of using inheritance. Exists an soluction for this? I want a solution similar to this: create_table :people |t| do t.column :name t.column :address end create_table :customer |t| do t.column :person_id t.column :cpf end create_table :employee |t| do t.column :person_id t.column :wage end class Person < ActiveRecord::Base end clas Customer < Person end class Employee < Person end Cusotmer.name Customer.cpf Employee.name Employee.wage -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
To my knowledge rails only supports STI or separate tables for each subclass. If you make People abstract then each subclass will be in its own tale. The hybrid you show is not directly supported. You would need to model them as associated tables. But, if you think about it that makes sense. How would you expect a row in the employee table to connect to a row in the people table? The best way is to add a people_id to employee. That becomes a :belongs_to and you are all set. You can always add support in Employee for delegating to the associated people object so to the user they appear to be subclasses. Michael On May 28, 12:06 pm, Marcelo Junior <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I search an plugin or gem, but don''t find nothing satisfactory. I > believe to be stranger a technology that nails the DRY, have that create > you vary equal tables, instead of using inheritance. > > Exists an soluction for this? I want a solution similar to this: > > create_table :people |t| do > t.column :name > t.column :address > end > > create_table :customer |t| do > t.column :person_id > t.column :cpf > end > > create_table :employee |t| do > t.column :person_id > t.column :wage > end > > class Person < ActiveRecord::Base > end > > clas Customer < Person > end > > class Employee < Person > end > > Cusotmer.name > Customer.cpf > > Employee.name > Employee.wage > > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MichaelLatta wrote:> To my knowledge rails only supports STI or separate tables for each > subclass. If you make People abstract then each subclass will be in > its own tale. > > The hybrid you show is not directly supported. You would need to > model them as associated tables. But, if you think about it that > makes sense. How would you expect a row in the employee table to > connect to a row in the people table? The best way is to add a > people_id to employee. That becomes a :belongs_to and you are all > set. You can always add support in Employee for delegating to the > associated people object so to the user they appear to be subclasses. > > MichaelThis is not inheritance, but relationship. What I want inheritance. Some plugin or gem? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
CTI = DRY -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
In Rails you can use STI very easily. The following example should clearify things (from Agile Web Development with Rails, you should buy the book at http://www.pragmaticprogrammer.com/ ): create_table :people, :force => true do |t| t.column :type, :string # common attributes t.column :name, :string t.column :email, :string # attributes for type=Customer t.column :balance, :decimal, :precision => 10, :scale => 2 # attributes for type=Employee t.column :reports_to, :integer t.column :dept, :integer # attributes for type=Manager # - none - end class Person < ActiveRecord::Base end class Customer < Person end class Employee < Person belongs_to :boss, :class_name => "Employee" , :foreign_key => :reports_to end class Manager < Employee end Customer.create(:name => ''John Doe'' , :email => "john-Ch9RrZxMC0c@public.gmane.org" , :balance => 78.29) wilma = Manager.create(:name => ''Wilma Flint'' , :email => "wilma-d1FEnVXDQDs@public.gmane.org" ,:dept => 23) Customer.create(:name => ''Bert Public'' , :email => "b@public.net" ,:balance => 12.45) barney = Employee.new(:name => ''Barney Rub'' , :email => "barney-d1FEnVXDQDs@public.gmane.org" ,:dept => 23) barney.boss = wilma barney.save! manager = Person.find_by_name("Wilma Flint" ) puts manager.class #=> Manager puts manager.email #=> wilma-d1FEnVXDQDs@public.gmane.org puts manager.dept #=> 23 customer = Person.find_by_name("Bert Public" ) puts customer.class #=> Customer puts customer.email #=> b@public.net puts customer.balance #=> 12.45 Regards, Bas --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Marcelo Junior wrote:> I search an plugin or gem, but don''t find nothing satisfactory. I > believe to be stranger a technology that nails the DRY, have that create > you vary equal tables, instead of using inheritance. >Take a peek at http://clti.rubyforge.org/ . It''s still only for PostgreSQL though. -- Sava Chankov --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- what do you think about write.table(... qmethod = "excel")?
- Ferret 0.10.2 - Index#search_each() and :num_docs
- R-beta: offset and glm again
- problem with 'svyby' function from SURVEY package
- Browsing with duplicate names in multiple workgroups/subnets and multihome machines