laravel-enso / people

Person management dependency for Laravel Enso
MIT License
5 stars 6 forks source link

Duplicate keys detected #6

Closed mauthi closed 5 years ago

mauthi commented 5 years ago

I have the following situation:

If I open people table I get the error: Duplicate keys detected and 2 lines are shown

Query for people table should be grouped by people id.

Btw.: The user_id is shown in people table and not the person_id

mauthi commented 5 years ago

2 other things:

aocneanu commented 5 years ago

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".

mauthi commented 5 years ago

Ok. So the only missing thing is why the id of user is shown in people table and not the id of person.

aocneanu commented 5 years ago

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?

mauthi commented 5 years ago

Output:

screenshot 2019-01-26 14 44 41

Response for the output above:

screenshot 2019-01-26 14 45 57

Really strange...

aocneanu commented 5 years ago

what's strange? You have two people, one with the id of 32 and one with 33.

mauthi commented 5 years ago

Yes, but in table I see 1, 2, 3, 4 which are the user ids?

mauthi commented 5 years ago

Ahh sorry, that table is configurated to show the line number - I changed other tables to show the id. Sorry sorry

aocneanu commented 5 years ago

1,2,3,4 is the current number :D

aocneanu commented 5 years ago

can we close this?

mauthi commented 5 years ago

yes