Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Aug 15, 2024
1 parent 6ffbe5f commit 6178840
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,28 @@ class NullPlan
def pro? = false
def ent? = false
end
```

```ruby
class Account
belongs_to :plan, optional: true, null_object: NullPlan.instance
end
```

```ruby
account = Account.create

puts account.plan # => #<NullPlan>
puts account.plan.free? # => true
puts account.plan.ent? # => false

account.update(plan: Plan.new(ent: true))

puts account.plan # => #<Plan id=1>
puts account.plan.free? # => false
puts account.plan.ent? # => true
```

## Supported Rubies

**`null_association` supports Ruby 3.1 and above.** We encourage you to upgrade
Expand Down

0 comments on commit 6178840

Please sign in to comment.