last day (14 days later) » 

3:52 PM
0
Q: Polymorphic relation with inherited model

JeetI have used polymorphic relation in one of my task having inherited models like Class Organization < ActiveRecord::Base end Class Company < Organization has_many :roles, as: :authorizable end Class User < ActiveRecord::Base has_many :roles, as: :authorizable end Class Role < ActiveRecord:...

 
Thanks Jubobs
But table doesn't exist with name 'company'. Only model exist
 
I think that's what happens when you use a inherited model, how did you add data of company's roles? you wrote authorizable_type property to 'Company' by hard code?
 
It was hard coded before i have started working on it.
 
So that's the problem, you should build relations like that: company.roles << roles. Then it will be ok.
 
But it would be on database entry time, but what would be the case when i want to fetch records from database..?
 
3:52 PM
I think company.roles << roles then company.roles will be fine. Open you rails console and have a try.
 
So in 'company.roles << roles', what would be 'roles'
 
still does't work?
 
No
it gives me blank array
 
what's the log of company.roles << roles
 
look, i have company = Company.find(company_id)
and i am trying to fetch roles for that particular company
Are you getting my question...?
 
4:00 PM
Sorry I had to leave, Dont kown why this does's works. Wait for others's answer.Bye
 
No problem Raymond Liu, Thanks for you precious time
Hope someone will post soon
 

last day (14 days later) »