Skip to main content

equals

Returns true if the argument is the same Dream class with the same primary key value, and both models are persisted.

Models derived from the same database record are equal even when they are different instances and even when the data has been changed in one instance but not the other. If you want to compare the attribute values of two models, see getAttributes.

const node = await GraphNode.create({ name: 'Hello' })
const reloadedNode = await GraphNode.find(node.id)
node.equals(reloadedNode)
// true

reloadedNode.name = 'Goodbye'
node.equals(reloadedNode)
// still true!
```

Models derived from different database records are NOT equal:

```ts
const node1 = await GraphNode.create({ name: 'Hello' })
const node2 = await GraphNode.create({ name: 'Hello' })
node1.equals(node2)
// false

Instances that have not yet been persisted are NOT equal:

const node1 = GraphNode.new({ name: 'Hello' })
const node2 = GraphNode.new({ name: 'Hello' })
node1.equals(node2)
// false