-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
Add ability to use complex data types and casts #118
Conversation
Currently Sushi inserts rows straight into the database, which does not allow any "complex" data to be saved in rows, not even an array. Think of the use case [ "county" => "SomeCounty", "postCodes"=>[111,222,333]] This change adds the ability to use $casts, which allows Eloquent to cast arrays and other data as necessary into/from a string for saving to the database.
The checks seem to fail due to a database connection problem. The code works on my application. |
This is pretty cool
|
Thanks, I added tests and used |
@calebporzio This is a cool feature but I think there needs to be a way to have casts and use the bulk insert. We have a sushi model that has ~ 500 rows. We use casts so data is nice when we retrieve it from the model and the initial data is set up correctly for when it is inserted anyway. Before this PR, it would be inserted as 5 queries based on the default chunk size of 100. |
@craigpotter What do you mean with:
Do you mean that you had a way to use casts before this PR? Because I could not see one, certainly not one that uses the simple casts included in Laravel. As the author of the PR, I tried to preserve the bulk-insert functionality, but could not see a way to do it. The original bulk insert method used the underlying DB directly; this does not call any casts or events whatsoever. The only way I could see to use casts was to manipulate data through Eloquent, but then each row must be inserted separately. Am I missing something here?
|
Just as a note:
and set your casts
it isn't perfect but it works for simple stuff anything more complicated should not use arrays i would suggest |
Currently Sushi inserts rows straight into the database, which does not allow any "complex" data to be saved in rows, not even an array. Think of the use case
This PR adds the ability to use the model's
$casts
, which allows Eloquent to cast arrays and other data as necessary into/from a string for saving to Sushi's internal SQLite database.