-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Eloquent models isGuardableColumn() calls fail on models that have a schema name in the table property #33822
Comments
Your model has a |
The only issue with that seems to be that I would need to add 20+ new config items to my My thinking for this being a bug is that the |
We've decided that we won't pursue backwards compatibility for this undocumented and unintended feature sorry. You should be able to get the behavior you want by overwriting the |
That's disappointing, but thanks for taking a look. |
We ran into this issue as well. After using laravel for many years I hadn't realized that specifying a different schema/database name on the table property wasn't documented. We ended up setting our uses of guarded to an empty array or removing them instead of switching to separate connections per schema. I did take note that we likely will need to switch to multiple connections at some point since specifying the schema with the table name isn't officially supported. |
@zhuston you can still use the connection property for that |
@driesvints Thank you. Primarily I was looking for the path of least resistance in order to get through with the upgrade. Our app has roughly 100 models that span 2 schemas/databases (same host). I had some concern that relations across separate connections might have issues. (they work fine now with database.tableName on the table property). I thought I read some people had issues with whereHas across connections since it creates a subquery? I also had a minor concern for doubling up our connections to our database server with each request opening 2 connections. That would certainly be solvable if it was an issue, but for now it seemed the the easiest path was changing our usage of guarded. Thank you for all of your work on Laravel! |
Description:
I've been using Laravel in a complex database setup pretty successfully for a while now by specifying the database name in my models'
$table
properties.As of #33777, all of my models that have defined a
$guarded
property instead of$fillable
have stopped working with mass assignment if the model also specifies a schema name in it's$table
property.I've been successfully using eloquent in this setup for a couple years now, as it is much easier than defining all of the connections individually (I'm using Laravel to interface with up to 25 schemas on a single server). We also have cross schema relationships (legacy data is fun), and this all works wonderfully prior to #33777 having been merged.
I realize this is not a documented feature, and may not even be officially supported, but it does make my life a lot easier and this genuinely feels like a bug to me.
Steps To Reproduce:
$table
propertyxxx column doesn't have a default value.
Specifically I did the following
$ composer create-project --prefer-dist laravel/laravel=6.18.8 issue-test
issuetest
)issuetest
, andissuetest2
)$ php artisan make:migration create_test_tables
$ php artisan make:model Test1 && php artisan make:model Test2
Potential Fix?
The issue appears to be all the way down in
Illuminate\Database\Schema\MySqlBuilder
. ThegetColumnListing()
method does not work for tables denoted byschema.table
.The following change works for both models, but I'm sure there's a better way to write it, this was just a quick test. I'm also sure there's angles I'm not thinking of here.
Thanks for taking a look.
The text was updated successfully, but these errors were encountered: