CSE 300 Software Engineering CSE 300 CSE 300

  • Slides: 6
Download presentation
CSE 300 - Software Engineering CSE 300

CSE 300 - Software Engineering CSE 300

CSE 300 - Software Engineering Discussion Items • Rails: Models • Rails: Form helpers

CSE 300 - Software Engineering Discussion Items • Rails: Models • Rails: Form helpers • Rails: Association 2 by Manish Shrotriya

CSE 300 - Software Engineering Rails Models • A model represents: – a object/entity

CSE 300 - Software Engineering Rails Models • A model represents: – a object/entity that has some interaction with end user. User can perform CRUD operations on these objects from a remote location through http. – a database table corresponding the object it represent. • Can have relation: – To accurately represent an OO system Rails support associations between models. Association is a way to specify OO relation between to model. 3 by Manish Shrotriya

CSE 300 - Software Engineering Rails Form Helpers • Html provides different from elements

CSE 300 - Software Engineering Rails Form Helpers • Html provides different from elements to show or to take data from the user. • Using Form helpers one can bind model data to different html form elements. Once bound the data can be easily be shown or retrieved from the user. • From helpers can work with model associations too. 4 by Manish Shrotriya

CSE 300 - Software Engineering Rails Associations • One to one – belongs_to: declaring

CSE 300 - Software Engineering Rails Associations • One to one – belongs_to: declaring model has reference to the foreign model • Ex: A belongs_to B A has reference of B – has_one: foreign model has reference to the declaring model • Ex: A has_one B B has reference of A • One to many – has_many: foreign model has reference to the declaring model. Declaring model has collection of foreign model • Ex: A has_many B B has reference of A, A. b is an array. 5 by Manish Shrotriya

CSE 300 - Software Engineering Rails Associations • Many to many – It is

CSE 300 - Software Engineering Rails Associations • Many to many – It is given by association: has_and_belongs_to_many objects of declaring model are related to many objects of foreign model – Declaring model has collection of foreign Model – separate table would keep the reference of both declaring and foreign model. It keeps the track of the information about which object of declaring model is related to which object of foreign model • Ex: A has_and_belongs_to_many B a separate table (Ex: A_B) has reference of both A and B. A has collection of B. 6 by Manish Shrotriya