tailieunhanh - Rails for Java Developers phần 5

Ngôn ngữ Ruby được thiết kế nhằm theo nguyên tắc ít gây ngạc nhiên nhất (principle of least surprise-POLS), nghĩa là ngôn ngữ hoạt động theo một cách trực quan hay ít nhất đó cũng là nhận xét mà các nhà lập trình đưa ra. Nguyên tắc này không xuất phát từ Matz và, nói chung, Ruby gần với suy nghĩ ít ngạc nhiên nhất của 'Matz' hơn. | Associations and Inheritance 123 With Hibernate you have to do a lot of repetitive work. You end up describing an association in three places the data schema the model classes and the Hibernate configuration. Hibernate developers often use code generation to reduce the amount of repetition involved or developers on Java 5 may choose to use annotations. With ActiveRecord there is less repetition You create only the data schema and the model classes. The configuration is in a more appealing language Ruby instead of XML. However more consolidation is still possible. ActiveRecord could infer much more from the schema. We hope that future versions of both ActiveRecord and Hibernate will infer more from the database schema. in addition to one-to-many ActiveRecord also supports the other common associations one-to-one and many-to-many. And ActiveRecord supports through associations that pass through an intermediate join through associations table. ActiveRecord also support polymorphic associations where at p lym rpliicassociations least one side of the association allows more than one concrete class. For more about these relationship types see Agile Web Develpment with Rails TH06 . Modeling Inheritance in the Data Tier In previous sections we discussed associations relationships from the data world that O RM tools propagate into the object world. We can also go in the opposite direction. inheritance is a concept from the object world that O RM frameworks can map to the data world. since inheritance is used to model hierarchy we will use a hierarchy you may remember from grade school celestial bodies. Under the base class CelestialBody one might find Star and Planet to name a few. Here is a simplified table definition Download code rails_xt db migrate create_table celestial_bodies do t shared properties name string type string star properties magnitude decimal classification char planet properties

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.