shrinerb / shrine-mongoid Goto Github PK
View Code? Open in Web Editor NEWMongoid integration for Shrine
Home Page: http://www.mongoid.org/
License: MIT License
Mongoid integration for Shrine
Home Page: http://www.mongoid.org/
License: MIT License
Hey @janko-m,
I've just found another bug I believe, because I was trying to do exact same thing as you described here:
https://github.com/shrinerb/shrine/blob/master/doc/multiple_files.md
But with Mongoid (and currently supported embedded models on my branch), and well, it just skips all the Shrine uploaders stuff (kind of). It just saves file_data
(if file attribute is just called file
), but there's no uploading or validations. (I must use Mongoid 6.4 though).
It looks like including ImageUploader::Attachment(:image) breaks mongoid callbacks for that model.
after_save
becomes unavailable and start getting no method errors
Hi!
In mongoid you have another relation type: embeds_one
/embeds_many
+embedded_in
.
This is an analog for has_one
/has_many
+belongs_to
, but in case of embedding - embedded model will be saved as a nested JSON object inside it's parent object, instead of a standalone object (record) in separate collection ("table").
That's quite common practice to have embedded models in mongoid, and in most cases it totally makes sense to use this approach for some "Attachment" model.
But there is slight problem with that - it's not possible to find such embedded model using code like this: Attachment.find(id)
.
Instead one should find parent record first, and then search for that attachment by its id
inside parent's attachments
collection, like this: parent_record.attachments.find(id)
So this means that the following code won't work:
class TranscoderUploader < Shrine
plugin :backgrounding
Attacher.promote { |data| TranscodeJob.perform_async(data) }
end
Because the data
hash contains data like this:
{ ..., "record"=>["Attachment", "5bbb71b79bf2cc634c187a24"], ... }
So it actually tries to find attachment record like this: Attachment.find('5bbb71b79bf2cc634c187a24')
, and we already know that won't work.
I got no idea how to make it work on this gem level "out of box", meanwhile I will try to come up with some workaround for this issue, and I will leave it here once I find it.
UPDATE
I meant that this code inside TranscodeJob
won't work actually:
def perform(data)
attacher = TranscoderUploader::Attacher.load(data)
...
end
So maybe that's not an issue at all, because it's my custom sidekiq job code is not working, not shrine's. I just was relaying on shrine's Attacher.load
code, and now it's just not enough :)
Hello.
I have "E11000 duplicate key error collection: project_db.users index: id dup key..."
I investigate this and noticed, that problem in embeded models with cascade_callbacks: true option. This case actual only for new models.
Because this callback called inside insert workflow:
https://github.com/shrinerb/shrine-mongoid/blob/master/lib/shrine/plugins/mongoid.rb#L95
and inserted parent record before main insert executed.
Thanks!
Rails 6.0.1
Mongoid 7.0.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.