0

I am working in rails 2, I have one table users and other table lms_users. In lms_users table, id from users table is coming as foreign key.

Association in users model

has_one :lms_user
has_one :group_detail , :through => :lms_user

Association in group_details

has_many :lms_users
has_many :users , :through => :lms_user

Association in lms_users

belongs_to :user
belongs_to :group_detail

I am joining tables like this

   @users = User.find(:all, :include => [:lms_user, :group_detail], :conditions => {:status => [1,2,3]})

but, when i try to access attributes of lms_user.. i get this error

NoMethodError in Lms_users#index
Showing vendor/plugins/redmine_leaves_management/app/views/lms_users/index.html.erb where line #15 raised:
undefined method `job_joining_date' for nil:NilClass

Extracted source (around line #15):

12:   <tr>    
13:     <td><%=h user.firstname %> <%=h user.lastname %></td>
14: 
15:     <%if user.lms_user.job_joining_date.blank? %>
16:         Employee Joining Date is Empty
17:     <%else%>
18:         <td><%=h user.lms_user.job_joining_date.strftime('%Y-%m-%d') %></td>

I am unable to find out reason.

Salil
  • 46,566
  • 21
  • 122
  • 156
Bilal Ahmed
  • 423
  • 1
  • 6
  • 11

0 Answers0