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

61 views
Skip to first unread message

pleasepressp

unread,
Mar 8, 2012, 5:28:59 PM3/8/12
to spi...@googlegroups.com
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


pleasepressp

unread,
Mar 9, 2012, 7:12:53 AM3/9/12
to spi...@googlegroups.com
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

Paul Young

unread,
Apr 25, 2012, 11:31:40 AM4/25/12
to spi...@googlegroups.com
It sounds like something is incorrect in your code.
Reply all
Reply to author
Forward
0 new messages