Comments (4)
I believe the callbacks on embedded documents are not fired when the parent is saved. From the Mongoid docs:
Callbacks are available on any document, whether it is embedded within another document or not. Note that to be efficient, Mongoid only fires the callback of the document that the persistence action was executed on.
mongoid_token uses callbacks to set the token, so in order to have embedded documents with tokens, you'll need to add the cascade_callbacks
option to your relation. This is the example from the docs:
class Band
include Mongoid::Document
embeds_many :albums, cascade_callbacks: true
embeds_one :label, cascade_callbacks: true
end
Hope that helps - let me know if you have any further issues.
from mongoid_token.
That works perfectly, thank you!
I have one follow-up question. When I try to use the monkeypatched find
in one of those embedded documents like:
stack = StackDef.find(params['stackid'])
component = stack.stack_components.find(params['componentid'])
Or even just:
component = StackDef.find(params['stackid']).stack_components.find(params['componentid'])
find
seems to revert to only accepting the mongo ObjectID, rather than the oid and the token. Any idea what's going on there? I've taken to using find_by
and just directly searching for the token, but it'd be nice if I was just doing something stupid.
from mongoid_token.
Sorry for the delay on this one @Igneous - I was able to replicate your issue, and have added a failing test case. I know it's probably too late you help you on whatever you were working on at the time - but I'm going to see about getting this patched ASAP.
from mongoid_token.
@Igneous After exploring this for a while, I think it's confirmed my long-held suspicion that monkey-patching find
is a pretty horrible way to handle things.
In the next big release of this gem, I plan on exploring adding support for using the token as the _id
field, which would negate the need for the monkey patched finders (Here: #8). I'll close this issue for now, as I think the solution is to use the find_by_*
query methods, which was your solution.
Thanks heaps again for all your feedback.
from mongoid_token.
Related Issues (20)
- Generate tokens for old Documents? HOT 1
- another define_method() issue? HOT 4
- Feature Request: Add rake or inline rails ability to generate tokens
- undefined method `args' in token.rb HOT 1
- Rails Admin has_many relations fail to save HOT 4
- Please specify a licence HOT 2
- Gem naming HOT 1
- not working in embed document? HOT 2
- Can i use token as foreign key? HOT 4
- Readme should say `bundle install` not `bundle update` HOT 1
- Cannot ensure unique token on embeded documents HOT 3
- Is there any plans for mongoid 5? HOT 2
- Is there a way to generate token without saving the actual document
- Feature Request: allow regenerate_token HOT 2
- Class.clone yields NoMethodError HOT 3
- Allow Mongoid 5.1
- Mongoid 6 support HOT 3
- uninitialized constant Mongoid::Token::Collisions
- Feature: Human friendly token generation (Idiot proof)
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 mongoid_token.