Kory
Kory

Reputation: 477

How to query (EBean & Play Framework) to see if a certain value is in a certain column in a certain table?

So, I have set up a registration form that saves info to a database in Play Framework. Don't get caught up on the nonexistant password security, I haven't gotten to that.

I need a way to check to see if an email is already in the user database. I'm simply not sure how to do that with Ebean.

The form model is stored here: https://github.com/Axsel/PonyCentral/blob/master/app/models/RegisterForm.java | In the validation method seen at the bottom of the class I need to be able to check the user table for any matching emails. The email variable from RegisterForm is direct input from the form.

The user model that is connected to Ebean can be found here: https://github.com/Axsel/PonyCentral/blob/master/app/models/User.java

Lastly, if you need to see it, the form request handler can be found here: Under /app/controllers/User.java (StackOverflow won't let me link for than two things)

If you could provide any help I would be very grateful.

Thank you much.

Upvotes: 0

Views: 1335

Answers (1)

biesior
biesior

Reputation: 55798

Just... query the database i.e. count the records for given email (written from top of my head):

int count = User.find.where().like("email", "[email protected]").findRowCount();
if (count>0) return badRequest("This email address already in use");

Upvotes: 1

Related Questions