开发者

Associate two tables one-to-many in rhodes

开发者 https://www.devze.com 2023-03-06 20:00 出处:网络
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#associationsbut I guess there is som

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 adde开发者_开发百科d:

@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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消