Extend user model - somehow I've broken verification


#1

I’ve extended my user model using the instructions at https://learn.userfrosting.com/recipes/extending-the-user-model#extend-the-user-model. Everything seems fine but I had only been testing locally. Having deployed to a staging server, I realize it has broken the verification page - when I click on the verification link, I get a 500 error.

From the log it’s very clear what is wrong, but I’m not sure where to go in order to fix it:

  • The query generated in the account sprinkle is correctly loading in the member table details, but the ‘where’ clause has just ‘id’ - and there are multiple ‘id’ columns in the query:
    select users.*, members.email_consent as email_consent, members.tc_agree as tc_agree, members.auto_renew as auto_renew, members.subscribed_until as subscribed_until, members.city as city, members.country as country from users left join members on members.id = users.id where id = 12345 and users.deleted_at is null limit 1

This gives me “Message: SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘id’ in where clause is ambiguous”

Did I miss a key step? (I looked at the verify function in the AccountController.php file but couldn’t see an obvious fix).

Many thanks for any help!


#2

Update: I found a solution. Comments on this solution would be welcome.

I identified the bit of code that was appending ‘where id = 12345’ to the Builder query and it was in the account sprinkle in src/Repository/TokenRepository.php on line 102:
$user = $this->classMapper->staticMethod('user', 'where', 'id', $model->user_id)->first();

I found that replacing this with the following fixed my issue:
$user = $this->classMapper->staticMethod('user', 'where', 'users.id', $model->user_id)->first();

I then had to figure out how to do this in my own extend-account sprinkle. To do this I did the following:

  • added a modified route for /verify so it uses my sprinkle
  • duplicated the repository folder from the account sprinkle and made my edit to TokenRepository.php
  • added a modified ServicesProvider.php file so I could reference my repository files

It now appears to work. It seems highly likely that there would be a better way of doing this, so I’d be very grateful for any feedback. Thanks!


#3

I don’t know enough yet to offer insight on a better way but am myself trying to extend the users table (following direction from the migrate documentation) and have found that my login/logout action generates an error but still gets me in. Does not look like I’m getting the error you showed though. I’m going to create a different topic in the forum to see if I can get some insight on the root cause of this one …

Illuminate \ Database \ QueryException (HY000)
SQLSTATE[HY000]: General error: 1364 Field ‘user_id’ doesn’t have a default value (SQL: insert into account_graphs_userprefs (id) values (1))