Can't display JSON correctly from different PostGreSQL tables

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
I want a user to click on a pin on a map that's on my front page and the pin will have a message popup bubble with some data being displayed.

The pin itself is on a Pins table in PostgreSQL and has a unique pin_id and the pin JSON has an "activity" key.

The pin's pin_id is attached to a guide_id on a separate Guides table and that JSON has a "first_name" key. The Guides table displays a list of all guides (people who can show you around the area of the pin drop).

Code:
function getPinData(id, template) {
  $.ajax({
    url: "/api/pins/"+id,
    type: "GET",
    data: "JSON"
  }).success(function(data){
    var pinTitle = data["pin"]["activity"];
    var pinGuideFirstName = data["pin"]["first_name"];
    console.log("Pin Title: " + pinTitle);
    console.log("Guide first name: " + pinGuideFirstName);
  })
}

The console log of pinTitle is correct.
The console log of pinGuideFirstName comes back as undefined.

This is how I have my .RABL file set up:

Code:
collection @pins, root: :pins

attributes :id, :title

node :first_name do |pin|
  pin.guide.user.first_name
end

When I go to the actual API URL (/api/pins) all the pins are displayed along with the pinGuideFirstName showing correctly.

Why is the first name showing up as undefined?
 

purbeast0

No Lifer
Sep 13, 2001
53,176
6,046
126
what is the backend that you are using?

just from quick glance, it sounds like on the backend you aren't mapping the data properly and when it is brought over to the front end it simply isn't there. i'm not really familiar with postresql, but since it is there on one call to the backend, but not when you are trying to access it in the success callback, that when mapping it on the backend something is going wrong.

give us the raw JSON output when you hit the url directly too, that could be helpful.