Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why there is not model id for Audit in Blameable behavior? #501

Open
Wayne-Wen opened this issue Dec 8, 2015 · 6 comments
Open

Why there is not model id for Audit in Blameable behavior? #501

Wayne-Wen opened this issue Dec 8, 2015 · 6 comments

Comments

@Wayne-Wen
Copy link

When I'm looking into the code of "Blameable" behavior, I found:

$audit->model_name = get_class($model);

Looks like it only stores the name of model. If I have two Products (Production A and Product B). And I have made changes on these two products. How can I know what are the changes of product A and what are the changes of product B. Because their model name are the same-----"Product", and there is not model id to distinguish them.

@endeveit
Copy link
Contributor

endeveit commented Dec 8, 2015

You can find information about changed data in "audit_detail" table.

@Wayne-Wen
Copy link
Author

@endeveit But How do you know whether the changed data is belonged to "Product A" or "Product B"?

@endeveit
Copy link
Contributor

endeveit commented Dec 8, 2015

You can use "field_name" field but I agree that current implementation of blameable behavior is poor and should be refactored.

@Wayne-Wen
Copy link
Author

@endeveit If "Product A" have changed its "name" from "apple 1" to "apple", and "Product B" have changed its "name" from "pear 1" to "pear". Here is an example:

audit table:

id user_name model_name ipaddress type created_at
1 Wen Product 127.0.0.1 U 2015-12-08 18:52:00
2 Peter Product 127.0.01 U 2015-12-08 18:53:00

audit_detail table:

id audit_id field_name old_value new_value
1 1 name apple 1 apple
2 2 name pear 1 pear

From these records, how do you know which row of audit_detail table is belong to "Product A"?
Like, when you look at the second row of audit_detail table, there is no data tells you if the row is belong to "Product A" or "Product B".

@niden
Copy link
Sponsor Member

niden commented Dec 8, 2015

@Wayne-Wen You can easily change this. Add two fields in your audit table:

usr_id <- the user that did this
record_id <- the id of the table/model that you are auditing.

Your table will then become

id user_name user_id record_id model_name ipaddress type created_at
1 Wen 4 13 Product 127.0.0.1 U 2015-12-08 18:52:00
2 Peter 4 14 Product 127.0.01 U 2015-12-08 18:53:00

@Wayne-Wen
Copy link
Author

@niden Of course, I have added a model_id field into my audit table and rewrote the Blameable class. But what is the purpose of Original `Blameable`` behavior since it cannot retrieve the changed of a model (like "Product A") ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants