Question: Are these 2 code snippets equivalent if the user's subscription has not been set:

```
user.subscription.nil?

```

and

```
user.subscription

```

In the models:
Subscription

```
belongs_to :user

```

User

```
has_one :subscription

```

Answer: 
If you want to check that the association is *not* present, these are equivalent:

```
user.subscription.nil?     # true if missing, false otherwise
user.subscription.blank?   # true if missing, false otherwise
!user.subscription         # true if missing, false otherwise

```

And if you want to check that the association *is* present, these are equivalent (in terms of truthy and falsey):

```
user.subscription.present? # true if present, false otherwise
user.subscription          # subscription if present, nil otherwise
!!user.subscription        # true if present, false otherwise

```
In User model,

```
has_one :subscription

```

In Subscription model,

```
belongs_to :user

```

Here the association has been defined between users and subsriptions table i.e. one-to-one.

So in rails, we are dealing the records as object. SO once you have user record, you can get its associate objects. In this case `user` is a object of User class.
So `user.subscription` returns the object of Subscription Class which contains the `user_id` equals to `user.id` .

And in some cases, there is no subscription for user. So we need to check before proceeding.
That's why we are using `user.subscription.nil?` or `user.subscription.blank?` or `user.subscription.present?`. These are returning boolean.

Here if user is having a subscription, then `user.subscription.nil?` returns `false` and if user don't have subscription, then it returns `true`.