Comments (3)
@bradleygreen, a lot of things has changed. In the past, we use to have a Document Assembler that would take an array from the database and then build an model. We took other directions to allow direct object unserialization from database. To fix your collections, you now need to have a __pclass
key on each document telling which class it belongs to.
Note: try this with a test database, not directly on production or some sensitive data!
// make sure to replace both occurrences of `\My\Namespace\Product::class` with your Product class
app(\My\Namespace\Product::class)->getCollection()->updateMany(
[],
[
'$set' => [
'__pclass' => new \MongoDB\BSON\Binary(\My\Namespace\Product::class, \MongoDB\BSON\Binary::TYPE_USER_DEFINED)
]
]
);
now, if you do:
\My\Namespace\Product::first();
it should work.
Basically you will need to do this to all of your collections.
You can leverage migrations to do this on production/etc:
php artisan make:mongolid-migration change_product_pclass
and create the logic, then run
php artisan mongolid-migrate
Refer to this documentation to learn more about __pclass
and mongodb serialization/unserialization.
I hope that it helps!
from mongolid-laravel.
Thank you for your response. We have been able to successfully create a test collection and update it to include __pclass. That test class did then work the way we are accustomed to using our Mongolid models.
We are concerned about implementation in one area. Will you please address it? How should we implement a class type for classes that sometimes (but not always) extend other classes (inheritance)?
As an example, we created a collection called 'products'. Its namespace is MyApp\Catalog\Product
. We then created a new website, using the same products collection, but that has a different getPrice() method so it could use different rules for the different site. So we created MyApp\Template\Product
, which 'extends' MyApp\Catalog\Product
and has only one method in it, but benefits from the methods on its parent class. We add the Template directory after the other directories in our auto-loader, so those classes get loaded instead of the base classes. We can then call either class, based on whether the Template namespace exists, by calling App::make("Product").
Can we add an alias instead of a namespace? How can we address class inheritance?
from mongolid-laravel.
Awesome! I was wondering if you managed to use it :)
There is a little friction migrating from v2, but it is worth it.
About "inheritance", we do have a concept that I think might work for you. It's what we call PolymorphableModel. Please take a look at PolymorphableModelInterface.
Basically, you make your base Product implement it, creating a polymorph
model which will tell which class mongolid must use for your model. There are some tests that might help understanding the concept.
We really need to update the documentation 😉
Please tell me about your progress!
from mongolid-laravel.
Related Issues (20)
- Support and Branch strategy HOT 1
- Migrations support HOT 2
- Mongolid Laravel Banner HOT 1
- Support for queue failed jobs HOT 2
- Laravel Socialite+Passport
- Undefined index: driver HOT 3
- How to write monogodb query log? HOT 2
- Support for laravel 7 HOT 1
- InvalidArgument - MongolidUserProvider::__construct expects MongolidLaravel\MongoLidModel, User::class provided
- How do relationship with mysql
- No suitable servers found (serverSelectionTryOnce set): [connection error calling hello on '127.0.0.1:27017']
- create legacy laravel model builder methods?
- Allow extend fillable and rules
- Clear errors
- Date Validation
- Search with aggretation and commands HOT 3
- Possible on PHP 5? HOT 3
- composer install problem with laravel v5.4.23 HOT 3
- Class 'MongolidLaravel\MongolidServiceProvider' not found HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongolid-laravel.