-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add hasColumn/hasColumns method #3001
Conversation
{ | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, that's a breaking change as you change the return value of this method. MongoDB doesn't have columns and there is no restriction on field names (unless you use a schema validation). I understand that this method is not useful as it is, as it returns always true
, but I don't think the proposed change is correct as it depends on the data in the collection. Which can lead to a different results depending on the data stored.
I agree with @GromNaN here. This method is essentially useless, because you're looking for "does any document in this collection have a field with this name". This is not something you should be checking for, and is also an extremely inefficient query as it's usually run unindexed, and thus relies on a collection scan and BSON inspection of every document in the collection. If there's a specific use case you'd like to change this method for, please share this use case with us, but I don't see any benefit in changing the current implementation. |
@GromNaN @alcaeus I want to share example why I added such code. So I have bitbucket pipelines configured to deploy project to virtual machine We use single Laravel project which works with migrations (mysql + mongo) So there an issue if went to keep mongo DB and reset only mysql
Will cause an error about existing unique key so I added some manual 'hasColumn' method to avoid such situation
|
Thanks for taking the time to give a little more context.
|
@GromNaN So what is the purpose of this method then? I beleive that returning always true is also not the right purpose here. I know, MongoDB is not using columns and also not tables but this package should handle MongoDB in this way, right? So when you don't like this approach, what do you think about to have a seperate method here? Schema::connection('mongodb')->table('table_name', function (Blueprint` $`collection) {
if (Schema::hasField('table_name', 'myField')) {
// My code ...
}
}); You already added the Here I understand why @Alex-Belyi created this PR. As I remember, not all laravel features are implemented in this package. Also this "try/catch" solution is not a real solution. Another issue can be that the migration table only exists in MySQL and not in MongoDB. |
Reopening. This feature would make sense as we just implemented |
Thank you @Alex-Belyi |
Co-authored-by: Jérôme Tamarelle <jerome.tamarelle@mongodb.com>
Add hasColumn/hasColumns method
Checklist