-
Couldn't load subscription status.
- Fork 92
Support mapping of entry data to database columns #273
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
Support mapping of entry data to database columns #273
Conversation
…ory and Query Builder (statamic#177) * Add upgrade note to readme * Begin split configs * Use form handle to relate, rather then a database id * Defer to core methods for retrieving submissions * Update fresh migrations and add migration for existing installs * Eloquent FormRepository * Fix migration * Dont force a model type or it can't be overwritten * Missing update script * Correct file path to migration * Lets not exclude parent * StyleCI * Actually run update script * Prep for Statamic 5 * Update dev dependencies * Try again * Meh * Remove deprecated test functions * static * Migrate PHP unit config * Fix migration * Fix tests to use handle instead of id * Bug fixes * Fix form listing bugs
* Split migration tags * fix everything * Merge branch '5.x-support' into split-migration-tags * Ignore `.phpunit.cache` --------- Co-authored-by: Ryan Mitchell <ryan@thoughtcollective.com>
* Simplify `TestCase` * Remove `partialMock` method from `TestCase` I'm not sure which "earlier versions of Laravel" this is referring to but the test suite seems to pass without it so I presume it's no longer needed. * doesn't look like we're using this method either * The `ConsoleKernel` isn't needed
* Eloquent driver should be opt-in, not opt-out * Swap all drivers to `eloquent` in our `TestCase`
* Fix asset import bug * Drop status on entries * Revert "Fix asset import bug" This reverts commit 35ebe65. * Fix test * StyleCI * Revert * Proper update script * Make status nullable in down migration
* Initial docs refresh * Fix tpyo * Missing space --------- Co-authored-by: Ryan Mitchell <ryan@thoughtcollective.com>
|
@duncanmcclean @jasonvarga would appreciate your thoughts on this when you get a chance. |
* Fix failing tests in `EntryQueryBuilderTest` * dont need to freeze time for this test
|
The statamic-5 branch has been merged, so this PR should target master. |
Just thinking out loud here.... instead of mapping the columns using a hook, is there any way the Eloquent Driver could figure out those columns itself, based on the columns in the database? Maybe it could get a list of the model's columns, filters out columns that already get mapped (like |
|
It could, but that would mean an extra query every time to get the columns. Not a hugely expensive operation but worth considering. It also limits us to root keys only - the current mapping approach could quite easily be extended to allow non-root keys. |
This PR makes it possible to store the contents of
datahandles in alternative columns in your database, eg you may want to storemy_keyin a column calledmy_key.The benefit of this is it allows you to index that column separately which can speed up database operations.
Mapping can be added by adding a hook on the eloquent entry class, and updating the array$payload. This array is a mapping of data handles to database columns (note that only root-level data keys are supported).The mapping 'auto-magically' happens by checking if a column in your entries table exists with the same name as your field handle, and where it finds it, it saves the field value there instead of the data column.
Following some discussion with Duncan, some additional thoughts:
If you are adding a migration to add a new column your schema based on an existing blueprint column, you'll need to save the entries to repopulate them
Entry::all()->each->save();as part of your migration.We're going to wrap this in a config to avoid it being a breaking change, so to enable this feature you'll need to set
statamic.eloquent-driver.entries.map_data_to_columnsto betrueCloses #272