UPDATE:
You need to add a new model called Favorite
and contains 2 fields: listing_id
and user_id
because the relation between users and favorites is many to many.
Or, you need to change the type of favorites in Listing
model to Array
like this way:
field :favorites, type: Array
Also, remove has_many :favorites ...
in User
model and add a getter method:
def favorites
Listing.where(favorites: self.id)
end
and a setter method:
def favorites=(listing)
Listing.find(listing.id).add_to_set(favorites: self.id)
end