Sathishkumar Jayaraj
Sathishkumar Jayaraj

Reputation: 646

How to check rails has_many records contain specified record?

I have User and Technology table. My association is User has_many technologies and not belongs_to user. I need to check whether the user contains particular technology or not

Example:

@technology = Technology.find_by_url "some_url"
@user = User.find params[:id]

Now i need to check whether the user has particular technology.

Upvotes: 2

Views: 358

Answers (1)

libcthorne
libcthorne

Reputation: 417

exists? can do this for you.

@user.technologies.exists?(@technology.id)

Upvotes: 4

Related Questions