Ruby on Rails CSE 190M, Spring 2009 Week 8. Models Up to this point, all of our work has been in our Controllers and View If you have inspected the Models.

Slides:



Advertisements
Similar presentations
Holiday Calendar Menu for navigation This is School Management System’s home screen. This application will automate School or College. It contains a Menu.
Advertisements

UNIVERSITY OF PALESTINE business computer application College of Business Instructor: Mr. Ahmed Abumosameh.
8 June Single table database in normal form Fields and records Normal form 1.Header in the first line 2.Same content for every field 3.Each record.
CIT 381 Slides part 3. Review: One-to-many and many-to-one One movie is stored on many videos – many videos are in one store. Both relationships are mandatory.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 4- 1.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 4 Enhanced Entity-Relationship (EER) Modeling.
CIT 381 More ER Modeling - review one-to-many - one-to-one - recursive relationships.
Entity-Relationship Modelling Introduced by Chen in 1976 The ER Model is used to construct the conceptual data model – independent of DBMS Most widely.
Information Resources Management January 30, 2001.
Database Design Chapter 2. Goal of all Information Systems  To add value –Reduce costs –Increase sales or revenue –Provide a competitive advantage.
Country/Network Admin
CIT 381 ER Basics - relationship types - foreign keys - ER Studio.
MS Access 2007 IT User Services - University of Delaware.
Database Relationships Objective 5.01 Understand database tables used in business.
Entity-Relationship Diagrams
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
RFID Parking Garage Matt Nichols Tony Nichols. Goals and Objectives To provide a parking system that is efficient and easy to use. To account for the.
Database Relationships. Types of Relationships One to one – Person to Driver’s License, Country to President, Person to Social Security Number (in theory)
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
Data Modelling – ERD Entity Relationship Diagram’s Entity Relationship Diagrams and how to create them. 1.
Principles of Database Design, Part II AIMS 2710 R. Nakatsu.
Prepared by: Guided by: Sagar Patel Prof. Chintan sir.
DATABASE DESIGN USING MICROSOFT ACCESS. What is a Database?  DMS Database management system  Database Collection of data organized in a manner that.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.
McGraw-Hill/Irwin ©2009 The McGraw-Hill Companies, All Rights Reserved Business Driven Information Systems 2e Plug-In T6: Basic Skills and Tools Using.
Chapter 2 Data Models Database Systems: Design, Implementation, and Management, Rob and Coronel Adapted for INFS-3200.
Data Model Property Inference and Repair
Ruby on Rails CSE 190M, Spring 2009 Week 6. Overview How to use a database Demo creating a blog application on Rails Explain how the application works.
The College of Saint Rose CIS 521 / MBA 541 – Introduction to Internet Development David Goldschmidt, Ph.D. selected material from Fluency with Information.
1 n 1 n 1 1 n n Schema for part of a business application relational database.
© Shamkant B. Navathe CC. © Shamkant B. Navathe CC Chapter 4 - Part I Enhanced Entity-Relationship and UML Modeling Copyright © 2004 Ramez Elmasri and.
1 Outline  What is a Primary Key?  AutoNumber primary keys  Single-field primary keys  Composite-field primary key  About Foreign Keys  Database.
Associations INFO 2310: Topics in Web Design and Programming.
Chapter 12 Entity-Relationship Modeling Pearson Education © 2009.
Microsoft Access Intro Class 6 Relationships.
1 Entity-Relationship Diagram. 2 Components of ERD: –Entity –Relationship –Cardinality –Attributes.
One Customer has Many Pets; One Pet as One Customer, so Customer ID goes on Pet Table. One Pet has many Visits, but only one Visit refers.
McGraw-Hill/Irwin © The McGraw-Hill Companies, All Rights Reserved TECHNOLOGY PLUG-IN T6 Basic Skills Using Access.
Database revision.
Instructor User Student User Course Registration Form (#8) Grade report (#14)Class list (#13) Grade Entry Form (#10)
Build a database III: Build relationships for a new Access database Overview: You can relate This course teaches you how to build relationships between.
Enhanced Entity-Relationship (EER) Modeling. Slide 4- 2 Chapter Outline EER stands for Enhanced ER or Extended ER EER Model Concepts Includes all modeling.
Entity Relationship Modeling
Social Roles and Relationships.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 4- 1.
System Modules Overview
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
Step 1of 11 Admin Demonstrations Click Here to Start.
Lecture 5 Entity Relationship Modeling
1 CSE 480: Database Systems Lecture 3: Entity-Relationship Diagram Reference: Read Chapter 3 (5 th Edition) or 7 (6 th edition)
WELCOME TO. Click on Products Click on SME Click on Online Products >> SME >> Taxbase Suite : Sales Module >>Read More…
Microsoft Access CS 110 Fall Entity Relationship Model Entities Entities Principal data object about which information is to be collectedPrincipal.
DATA SCIENCE MIS0855 | Spring 2016 Designing Data
ENTITY-RELATIONSHIP MODELLING. Objectives: How to use Entity–Relationship (ER) modelling in database design. Basic concepts associated with ER model.
Enhanced Entity-Relationship (EER) Model
Q TRACKER Tracking on the job training hours for Apprentices.
PHP Image Gallery Script |Image Selling Website PHP Script - PHP Images and Media Script Phpscriptsmall
From employee apathy to employee engagement
Practice of ER modeling
Sampath Jayarathna Cal Poly Pomona
Sampath Jayarathna Cal Poly Pomona
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modeling
Presentation transcript:

Ruby on Rails CSE 190M, Spring 2009 Week 8

Models Up to this point, all of our work has been in our Controllers and View If you have inspected the Models created by the Scaffolding, you will notice that they are empty – But they inherit from ActiveRecord::Base – This is what gives us access to the fields (methods) of the objects as they are in the database without defining the methods ourselves So… why do we even have models?

Models We use Models define methods that provide information about individual objects These methods usually do calculations on other properties of the object that you will not want to write over and over again Example: user.admin?# checks if a user is a admin user user.authenticate# authenticates a user gallery.empty?# checks if a gallery is empty gallery.clear# removes all the gallery images

Relationships Often, there are inherit relationships between the different object we are creating – In a blog Users have many Entries; an Entry belongs to only one User Entries have many Comments, and a Comment belongs to only one Entry – In a login system Users have many Roles; Roles belong to many Users – In a course registration system A Student has many courses; a course has many students

Types of Relationships One-to-One – A U.S. citizen has only one S.S.N; Each S.S.N. belongs to only one U.S. citizen One-to-Many – A person owns many cars; A car belongs to only one owner – A company has many employees; An employee is employed by only one company Many-to-Many – A student has many courses; A course has many students – A programmer has many projects; A project has many programmers – A blog post has many posters; A poster has many posts

Relationships in Models One-to-One – has_one/belongs_to One-to-Many (most common) – has_many/belongs_to Many-to-Many – has_many/has_many – has_and_belongs_to_many – These are tricky… So we will not go into detail with these An object that belongs_to another should reference that object by id in the database employee.company_id

Relationships in Models In Our Gallery Class class Gallery < ActiveRecord::Base has_many:images# plural: images end In Our Image Class class Image < ActiveRecord::Base belongs_to:gallery# singular: gallery end