-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetch column parent :name instead of :parent_id #63
Comments
Try this:
|
Hi @slenderock this will show me the current child name, I need to show the parent name |
Hello, @zippax
I guess "&" is required to prevent errors when parent doesn't exist for this record. |
Error if I change it to :parent_id will show me :
|
undefined method 'parent' for what class ? |
|
You should use active_record object(not id) if you want to get method #name. If you get "undefined method 'parent'" you probably forgot to set belongs_to association in your model. Btw, I have this line of code in my project and it works fine:
|
Actually the Category model have name and parent_id so there is no association between 2 models. both are in the same table
|
this is a Github repo https://github.com/zippax/cs |
Seems like you don't have parent model at all. So how you want to get parent name, if you don't have this relation? |
so I have to make subCategory model and make association between it and the Category model |
You should have this code for subcategory
|
and then you can use:
|
As @slenderock mentions, having the associations in place are the key to getting this working. One thing I would add is that in many cases, you can drop the custom block all together and just use: column :parent This will automatically display the parent instance (if present) by finding a method from It will also automatically link the name to a corresponding admin for the parent model, if it exists. |
the second column will show the id. I want to show parent name instead of the id.
The text was updated successfully, but these errors were encountered: