Samiron Rony wrote: > How did you write your Business and User models? > What you are trying to do is as simple as a relation between User and > Business model. And i guess it should be like the following: > > class User < AR::B > has_many :businesses # or > # has_one :business > end > > class Business < AR::B > belong_to :user > end > > Now if you have these setup as expected then what about your yml > files? Did you made the exact relationship there? If you have > businesses.yml and users.yml then a business object should have a > user_id which should refer a user id from users.yml > > With a proper relation with user_id of businesses table with id of > users table would return a user object if you call business.user and > then you can call whatever method of that user object. > However, could you please explain what is the user.login method doing > here?? > As you said >> >> foreign key e.g. it shows 'Graham' not 1 > > It should be like user.name or user.first_name or something else. But > login method doesnt seem that intuitive or im missing something? > > Let me know the status... > > Samiron paul > http://samironpaul.blogspot.com/
Hi Samiron, Sorry for the delay in replying. I've setup my business and user models as follows class Business < ActiveRecord::Base belongs_to :user class User < ActiveRecord::Base has_one :business In relation to the yml files please pardon my ignorance I take it that its the file in the Fixtures folder if so here they are please note the user_id I had to add myself. one: id: 1 name: Graham's Bar user_id: 1 address: 112 O'Connell Street province: Dublin 1 city: Dublin country: Ireland longitude: 1.5 lattitude: 1.5 two: id: 2 name: Joe's Bar user_id: 2 address: 12 Grafton Street province: Dublin 2 city: Dublin country: Ireland longitude: 22.4 lattitude: 22.5 In relation to the user.login I had to add that to display the users name not the id field data. The field login is setup by default by authlogic. If I'm leaving anything that you need out please let me know. Graham -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.