GithubHelp home page GithubHelp logo

shrinerb / shrine-mongoid Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 5.0 25 KB

Mongoid integration for Shrine

Home Page: http://www.mongoid.org/

License: MIT License

Ruby 100.00%
shrine mongoid attachment

shrine-mongoid's People

Contributors

funkyloverone avatar janko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

shrine-mongoid's Issues

Breaks mongoid callbacks

It looks like including ImageUploader::Attachment(:image) breaks mongoid callbacks for that model.
after_save becomes unavailable and start getting no method errors

Backgrounding for embedded models

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 :)

E11000 duplicate key error collection

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.