Active Record Flashcards

1
Q

find_in_batches

A

Yields each batch of records that was found by the find options as an array.:batch_size - Specifies the size of the batch. Default to 1000.:start - Specifies the starting point for the batch processing.

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

find_each

A

The find_each method uses find_in_batches with a batch size of 1000

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

column_names

A

Returns an array of column names as strings.

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

column_defaults

A

Returns a hash where the keys are column names and the values are default values when instantiating the AR object for this table.

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

User.where(‘name != ?’, ‘Gabe’)

A

Qureries the database for all Users where the name not Gabe

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

User.where(‘name = ? AND last_name != ?’,’Gabe’,’Smith’)

A

Queries the database for all Users where the name is Gabe and the last name is not Smith

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

User.where(‘age < 45’)

A

Queries the database for all Users where the age is less than 45.

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

Person.destroy_all(conditions: nil)

A

Destroys records of the Person model matching conditions, or all if no condition is passed. Each object’s callbacks are executed.

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

Person.delete_all(conditions: nil)

A

Deletes the records matching conditions without instantiating the records first, and hence not calling the destroy method nor invoking callbacks.

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

Person.pluck(:name)

A

Returns an Array of attribute values type-casted to match the plucked column names, if they can be deduced.

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