Tuesday, 13 September 2016

What is the difference between find and where query ?

If you will find any record by id or something else then, if the record would not be present find will return Exception error it can break your application. find a user who is not in a database like this:

User.find(:id=>6)

it's wrong to find data. Now try where instead of find because if the record would not be present where will return Nil it will not break your application. find a user who is not in a database like this:

User.where(:id=>6).first

That's why use where to get the record to the database in rails :)

2 comments:

  1. Software tester We always follow the latest trends in IT world and update our syllabus based on that information. Our students graduate with the knowledge of the latest technology that is used in Software Development and QA.

    ReplyDelete

Featured post

Difference between find, find_by and where

Hello, friends in the last post we have read about the difference between find and where, Today I will share how to use find to stop Exc...