Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8467309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:36:19+00:00 2026-06-10T15:36:19+00:00

I assumed this will work in my BatmanJS Controller: project = Project.find parseInt(params.id, 10),

  • 0

I assumed this will work in my BatmanJS Controller:

project = Project.find parseInt(params.id, 10), (err) ->
  throw err if err

@set 'project', project
**@set 'owner_id', project.get("owner_id")**

but project.get(“owner_id”) is always undefined. Im wondering if my call with Project.find is wrong, since i thought it is quite similar to rails. What am i doing wrong?

owner_id is an attribute of the project and valid in the view:

%p{"data-bind" => "owner_id"}

works and spits out the correct owner id.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:36:21+00:00Added an answer on June 10, 2026 at 3:36 pm

    Like many things in JS, Batman.Model.find is an asynchronous method, from the docs…

    Model.find() asks a model to call a given callback with the record with the given id.

    So, here’s the order of things as they’re happening in your code…

    1. Call Project.find which tells Batman.Model to call our callback function after it has retrieved the data from the DB.
    2. Assign the return value of that function (which is kind of a promise that will be filled in later).
    3. Set the 'project' keypath to that promise.
    4. Immediately try to call #get on that promise (before it has a value).
    5. Some time later the find returns from the DB and so project and therefore your 'project' keypath are updated with the value of your project – but 'owner_id' is still undefined.

    Fix this by not trying to set intermediate keypaths, but just directly binding to the attributes of your model in your views.

    Ie. have this in your controller…

    @set 'project', Project.find parseInt(params.id, 10), (err) -> throw err if err
    

    …and then this in your view…

    <p data-bind="project.owner_id"></p>
    

    When the project eventually arrives from the DB, that element will be updated with the owner_id

    Alternatively, if you want to do something with that owner_id value in your controller, then setup an observer for the keypath, that will be triggered when the project arrives from the DB, eg.

    @observe 'project.owner_id', (id) =>
      if id
        @set 'owner', Owner.find id, (e) -> throw e if e
    
    @set 'project', Project.find parseInt(params.id, 10), (err) -> throw err if err
    

    So, when the Project.find returns it will set the 'project' and in turn the 'project.owner_id' keypaths, which will trigger your observer to go and retrieve the Owner and set the 'owner' keypath. So now you could have in your view…

    <h3 data-bind="owner.name"></h3>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume a device has never seen another device before, in this setup it will
For this question, let us assume that we will want to show the face
Why/how does this create a seemingly infinite loop? Incorrectly, I assumed this would cause
I assumed that this would provide me with the list of follower names instead
I assumed joinable would indicate this, however, it does not seem to be the
Trying to figure out this pseudo code. The following is assumed.... I can only
Why do IDE's complain about leaking this in constructor? I've always assumed that it's
I'm sure this is very easy but I'm trying to get the fmdb sqlite
In pre-.NET world I always assumed that int is faster than byte since this
I work with a lot of monochrome image data and this morning I noticed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.