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

Only select columns that exist in the database #130

Merged
merged 1 commit into from Dec 15, 2017

Conversation

Projects
None yet
2 participants
@judahnator
Contributor

judahnator commented Dec 15, 2017

I have a model that has a few $appends attributes that do not exist in the database, that I need to serve in JSON responses in my application.

When Laravel Scout grabs the keys of the results of the toArray() method in its Searchable trait it also grabs all of the accessors defined in the $appends field.
https://github.com/laravel/scout/blob/3.0/src/Searchable.php#L199-L207

For example, I have an Article model that has an accessor to generate a field named "published_at_atom." This field does not exist in my database, only on the model.
In this packages current state, this is what I would get if I tried to run the tntsearch:import command:
image

All this proposed change does is retrieve the available columns from the models table, and intersect that with the desired columns from the toSearchableArray() method, and selecting only those.

This way this package does not attempt to select nonexistant columns.

@nticaric nticaric merged commit b1e5799 into teamtnt:master Dec 15, 2017

2 checks passed

Scrutinizer No new issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment