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

  • SEARCH
  • Home
  • 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 8839787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:18:56+00:00 2026-06-14T10:18:56+00:00

i’m a newbie in ember, and i’ve been scratching my head on this since

  • 0

i’m a newbie in ember, and i’ve been scratching my head on this since yesterday.
I want to make a simple Blog example using ember and rails with serializers.

I’ve been able to make the CRUD for posts, no problem. Most of the code is in the router.

I have a problem with my comments which are declared like that :

App.Comment = DS.Model.extend
   body: DS.attr('string')
   post: DS.belongsTo('App.Post')  

App.Post = DS.Model.extend
    title: DS.attr('string')
    body: DS.attr('string')
    comments: DS.hasMany('App.Comment',embedded: true)    

Displaying the comments of a post is ok, route looks like : /#/posts/:id/comments .

New comment link is on the bottom of the comments’list, so route for creating a new comment is :

/#/posts/:id/comments/new

At that point i hit the problem : how do i tell ember-data which post owns that comment ? I mean whart is the best practice for doing it ?

Finally i decided to initialize comment.post_id before displaying the form, coding it in the router. It looks like :

create: Em.Route.extend
   route: '/new'
   connectOutlets: (router, context) ->
      transaction = router.get('store').transaction()
      comment = transaction.createRecord(App.Comment)
      comment.set('post_id', router.get('postController').get('id'))
      router.get('applicationController').set('transaction', transaction)
      router.get('commentsController').connectOutlet
          viewClass: App.EditCommentView
          controller: router.get('commentController')
          context: comment
   save: (router, event) ->
       router.get('applicationController.transaction').commit()
       router.transitionTo('index')

But it doesn’t work, coming back to the server, the post request has no value for post_id.

I tried to add an input field for post_id in the form to check the value before saving and the value is there and correct.

I tried to debug the save function in the router which is fired when the form is submitted. Here too the post_id value is correct.

I must be missing something but hell i don’t know what …..

Philippe

  • 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-14T10:18:57+00:00Added an answer on June 14, 2026 at 10:18 am

    You should be setting the post on the comment, but not via the post_id property.

    Yes, post_id is how both your server and Ember Data will serialize the association’s foreign key, but that’s a detail Ember Data wants to abstract away from you. When interacting with your models, you shouldn’t know or care about how association data (or any data, really) is serialized by Ember Data and passed to the server. (In fact, unlike Rails, post_id will never actually exist as a property on your Comment records.)

    Instead, you should simply interact with the attributes and associations as defined in your models. If you have a Comment model with a post belongsTo association, then just use comment.set('post', post). It’s meant to behave like comment.post = post in Rails, taking care of all the details for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.