Comments (2)
Hi, thank you for spotting issue.
This fix should help in your case:
diff --git a/lib/abstract-class.js b/lib/abstract-class.js
index d5bc85c..599b4db 100644
--- a/lib/abstract-class.js
+++ b/lib/abstract-class.js
@@ -179,6 +179,7 @@ AbstractClass.find = function find(id, cb) {
substractDirtyAttributes(obj, data);
this.call(obj, data);
} else {
+ data.id = id;
obj = new this(data);
this.cache[data.id] = obj;
}
It's not pushed yet, because I'm in trouble with replicating it. Looks like
some non-jugglingdb code removing id for some reason, but I might be wrong
of course.
I came up with following test case, but it working fine:
+ it('should return id in find result even after updateAttributes',
function (test) {
+ Post.create(function (err, post) {
+ var id = post.id;
+ post.updateAttributes({title: 'hey'}, function () {
+ Post.find(id, function (err, post) {
+ test.ok(post.id);
+ test.done();
+ });
+ });
+ });
+ });
Code reviewing of find
method show that it fully rely on what database
adapter returned. It's not good, I agree, so I think would be fine just
specify id after finding record.
On Fri, Feb 17, 2012 at 10:26 PM, nesterko <
[email protected]
wrote:
Hi,
What I have experienced recently is that sometimes after
updateAttributes(), find() returns an object by id, but there is no id
element in it (so this property is undefined). This ends up interfering
with the code, so I ended up assigning id explicitly in the callback:7 before 'load role', ->
8 console.log "Looking up role id : " + params.id
9 Role.find params.id, (err, role) =>
10 if err
11 redirect path_to.admin_roles
12 else
13 role.id = params.id
14 @ROLE = role
15 console.log "Here it is : "
16 console.log JSON.stringify @ROLE
17 ## also load role privileges
18 role.privileges (err, privileges) =>
19 if err
20 redirect path_to.admin_roles
21 else
22 @roleprivileges = privileges
23 @roleprIDs = privileges.map (el) -> el.id
24 next()
25 , only: ['show', 'edit', 'update', 'destroy']One scenario when this happens is in the standard crud generation rw g
crud post title content --tpl jade, then rw server 8888, then create a
post, then click edit, then update post, then edit again.I do not know why sometimes find does not return id with the object, I am
having trouble recreating this in rw console.Thanks.
Reply to this email directly or view it on GitHub:
#31
Thanks,
Anatoliy Chakkaev
from jugglingdb.
Thanks for the help. I have just also experienced that all() also sometimes returns objects without id. Again, I am having trouble recreating it in rw console, but it happens in the slightly amended standard crud generated controller... Sorry can't provide more info for now.
from jugglingdb.
Related Issues (20)
- README documentation references are not reachable
- is this project dead ? HOT 5
- Potentially unhandled rejection [2] TypeError, when upgrading to new version of node. HOT 1
- Site down HOT 2
- Support multiple hooks per action
- Validations should be revisited
- Deprecate mutation features
- Consider removing all instance methods
- Disallow mixins on Model
- Model relations
- how to query field in multiple values? HOT 1
- Can i use JugglingDB in production? HOT 4
- process rpc message error TypeError: User.bulkUpdate is not a function HOT 2
- How can i delete one record ?
- Is this project maintained? HOT 2
- How to get the table definition from a datasource?
- upsert method doesn't trigger any hooks for mysql adapter HOT 3
- In
- Use in production? HOT 2
- Composite primary keys / composite foreign keys
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 jugglingdb.