Associate two tables one-to-many in rhodes

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? Thank you!

Answers


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.


Need Your Help

Must jQuery be verbose?

jquery jquery-ui

I see a lot of jQuery code like this:

How to sort DropDownButton items?

c# xml winforms

I populate DropDownButton by xml nodes

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.