Skip to main content

attributes

Attributes are usually set as part of create or update calls, or directly using dot notation (balloon.color = red and then calling balloon.save); however, there are times (e.g. when adding custom getters and setters that transform the data prior to persisting) when it is helpful to bypass the getters and setters.

Bypassing methods

getAttributes

Returns an object containing all the columns on this dream class, as well as their values, bypassing getters.

const user = User.new({ email: 'how@yadoin' })
user.getAttributes()
// {
// email: 'how@yadoin',
// ...
// }

getAttribute

Returns the value for a columnName provided, bypassing the getters.

const user = User.new({ email: 'how@yadoin' })
user.getAttribute('email')
// 'how@yadoin'

setAttributes

Takes the attributes passed in and sets their values internally, bypassing custom setters defined for these attributes.

const user = new User()
user.setAttributes({ email: 'my@email', password: 'my password' })

setAttribute

Changes the attribute value for a single attribute internally, bypassing custom-defined setters.

const user = new User()
user.setAttribute('email', 'sally@gmail.com')

Non-bypassing methods

assignAttributes

Takes the attributes passed in and sets their values, leveraging custom setters defined for these attributes.

const user = new User()
user.assignAttributes({ email: 'my@email', password: 'my password' })

assignAttribute

Changes the attribute value for a single attribute, leveraging custom-defined setters.

const user = new User()
user.assignAttribute('email', 'sally@gmail.com')