Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 2.35 KB

File metadata and controls

60 lines (47 loc) · 2.35 KB

Banking Challenge

Setup

rails generate model Owner name:string address:string

✅ ✅ ✅

rails generate model CreditCard number:integer exp_date:string owner_id:integer rails db:migrate

Challenges

Owner.create name:'Joe', address:'123 Cherry St' Owner.create name:'Chris', address:'976 Whatever Ln' Owner.create name:'Roger', address:'574 Kings Ct'

class CreditCard < ApplicationRecord belongs_to :owner <-- added to CreditCard model, linking CreditCard to Owner end

class Owner < ApplicationRecord has_many :credit_cards <-- added to Owner model, allows users to have multiple credit cards end

CreditCard.create number:'5555222233331234', exp_date:'01/29', owner_id:1 CreditCard.create number:'5564182249337684', exp_date:'08/26', owner_id:2 CreditCard.create number:'5698128998432295', exp_date:'05/23', owner_id:3

joe.credit_cards.create number:'5555222233335682', exp_date:'01/29' joe.credit_cards.create number:'1234987654326754', exp_date:'01/26'

Stretch Challenge

class AddCreditLimitToCreditCard < ActiveRecord::Migration[7.0] def change add_column :credit_cards, :credit_limit, :string --- created migration to add
credit_limit column to credit_cards table end end

all_cards = CreditCard.all all_cards.update credit_limit:'10000'

rails g migration change_data_type_of_credit_limit

class ChangeDataTypeOfCreditLimit < ActiveRecord::Migration[7.0] def change change_column :credit_cards, :credit_limit, :integer, using: 'credit_limit::integer' end end

joescredit.sum(:credit_limit)