Relations - Ajax - why is an update on related ModelB triggered after initial ModelA.fetch()

Showing 1-3 of 3 messages
Relations - Ajax - why is an update on related ModelB triggered after initial ModelA.fetch() pleasepressp 3/8/12 2:28 PM
Hi there,

hope I can get help ... I'm at loss

I have setup  2 models

User
Profile

User hasOne Profile
Profile belongsTo User

both extend Spine.Model.Ajax

when my App starts I do a User.fetch()

and retrieves a list of user with their related profile

[{"id":"1","username":"admin","email":"webm...@example.com","profile":{"id": 1, "user_id": 1, "firstname":"Administrator","lastname":"Admin"}}]

As I understand it the relations module creates my users profiles (user.profile()) - I can see that as using User.find(1).profile().firstname yields Administrator

BUT 

After the inital fetch is triggered a create action and an ajax call (POST) trying to update the profile

I don't understand the behavior here

I have tried to follow the logic in the debugger but can't seem to understand why this is done as my profile information is already up to date with my first request.

Hope some one can shed some light

let me know if I can give more infos

thnks


Re: Relations - Ajax - why is an update on related ModelB triggered after initial ModelA.fetch() pleasepressp 3/9/12 4:12 AM
Follow up and clarification

I'll try to clarify what the issue is for me

I am fetching records from the db through Ajax
These records have related (hasOne) models
Spine tries to create those related models in the db after the fetch

I've tracked it down to this:

As Spine has to create those related models on the client (for each record fetched)
If the Spine related model  extends Ajax
a create ajax call is sent
and new records for this related model are created on the server side
whereas they already exists

So I am wondering if I am completely wrong in saying that there should not be any ajax calls for related models after an initial fetch

thanks for any thought on this

thomas
Re: Relations - Ajax - why is an update on related ModelB triggered after initial ModelA.fetch() Paul Young 4/25/12 8:31 AM
It sounds like something is incorrect in your code.