GithubHelp home page GithubHelp logo

Comments (2)

1602 avatar 1602 commented on August 18, 2024

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.

nesterko avatar nesterko commented on August 18, 2024

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)

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.