Chapter 9 - Advanced Active Record Flashcards

1
Q

ORM

A

Object-relational mapping framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Scopes

A

Scopes (or “named scopes” if you’re old school) allow you to define and chain query criteria in a declarative and reusable manner.

scope :submitted, -> { where( submitted: true) }

scope :underutilized, -> { where(‘ total_hours > User.submitted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Scope class method

A
def self.delinquent
  where(' timesheets_updated_at
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Scope parameters

A

scope :newer_than, ->( date) { where(‘ start_date > ?’, date) }

BillableWeek.newer_than( Date.today)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Chaining scopes

A

scope :submitted, -> { where( submitted: true) }

scope :underutilized, -> { submitted.where(‘ total_hours

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

default_scope

A

we can use a default scope to simplify our general queries.

default_scope { where( status: “open”) }

> > Timesheet.pluck(: status)
= > [” open”, “open”, “open”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Arel

A

Arel is a SQL AST manager for Ruby. It

Simplifies the generation of complex SQL queries
Adapts to various RDBMSes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Callbacks

A

Callbacks can do a variety of tasks, ranging from simple things such as the logging and massaging of attribute values prior to validation to complex calculations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

before_save

A

before_save :geocode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

pluck

A

The pluck method queries the database for one or more columns of the underlying table of a model.

User.pluck(: id, :name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Polymorphic has_many Relationships

A

belongs_to :commentable, polymorphic: true

class Timesheet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

enum

A

Rails 4.1

enum status: %i( draft published archived)

> > Post.new.status = > “draft”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly