Question

I'm starting a new application in rhodes and I'm trying to associate two tables. I already tried doing what is suggested in http://docs.rhomobile.com/rhodes/rhom#associations but I guess there is something missing, because it is not working. This is what i did:

I have a Client table and a Photo table. A client can have many photos, but photos only one client. I added to my Photo.rb

belongs_to :client_id, 'Client' 

and added the following to client_controller:

photo = Photo.find(:first) # find the photo
photo.client_id = @client.object
photo.save
redirect :action => :index

As said in the link above, but when I try to create a new user it doesn't work.

I also added:

@photo = Photo.new

to the client_controller in new, and also added a field to enter some input to one of the fields in photo when creating a new Client. But again it doesn't work.

Do you have any suggestions?

Was it helpful?

Solution

Associations (belongs_to, has_many, ...) in rhodes are useful only for sync operations.
It indicates when to trigger a sync in certain objects, like its parent or childrens.
For other purposes (manipulating object relations) you need to do it by yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top