Closed mauthi closed 5 years ago
2 other things:
We got to the point where we needed in our applications a way to handle people that don't have access in the app at some point, but may have in the future.
Once the People structure was created we wanted to normalize the database. Before having People, the personal details for users were kept in the users table.
Our intention is to have a One to One relation - the Person
model has a user()
relation, without an s
The implementation does not allow creating more than one user per person (from the interface) unless you do something "under the hood".
Ok. So the only missing thing is why the id of user is shown in people table and not the id of person.
the query behind PeopleTable
should be:
return Person::select(\DB::raw(
'people.*, people.id as "dtRowId", CASE WHEN users.id is null THEN 0 ELSE 1 END as "user"'
))->leftJoin('users', 'people.id', '=', 'users.person_id');
people.*
will select the id of the person. There is no user.id in this select.
the request response as I see it is:
{id: 1, company_id: 115, title: "Mr", name: "Administrator", appellative: "Admin", uid: "admin",…}
appellative: "Admin"
birthday: "24-10-2018"
company_id: 115
created_at: "05-10-2017"
created_by: null
dtRowId: 1
email: "admin@laravel-enso.com"
id: 1
name: "Administrator"
obs: "13132222"
phone: "456"
position: "test"
title: "Mr"
uid: "admin"
updated_at: "2019-01-25 10:47:10"
updated_by: 1
user: 1
where user:1
is a boolean flag.
Could you be more precise?
Output:
Response for the output above:
Really strange...
what's strange? You have two people, one with the id of 32 and one with 33.
Yes, but in table I see 1, 2, 3, 4 which are the user ids?
Ahh sorry, that table is configurated to show the line number - I changed other tables to show the id. Sorry sorry
1,2,3,4 is the current number :D
can we close this?
yes
I have the following situation:
If I open people table I get the error:
Duplicate keys detected
and 2 lines are shownQuery for people table should be grouped by people id.
Btw.: The user_id is shown in people table and not the person_id