Linking twice between 2 models.

Skip to first unread message

Ben Edwards

Mar 17, 2019, 8:35:13 PM3/17/19
to rails_admin
I have 2 models and link twice between them. = walk_section_buttons.section_button_id = walk_section_buttons.next_section_button_id 

The first one gives me a drop-down/search box on the rails_admin screen to add a record to
walk_section_buttons but the second just has a field where I can type a integer. Is there any way to get the second working. I think I need to put something in the model, tried

class WalkSectionButton < ApplicationRecord
belongs_to :walk_section
belongs_to :next_walk_section_id, class_name: :walk_section

But is does not work.  How does rails_admin work out there is a foregn/primary key relation, what do I need to put in the model(s).


Ben Edwards

Mar 17, 2019, 8:37:06 PM3/17/19
to rails_admin
Sorry, formatting got messed up, should be:

Eduardo Moreno

Mar 18, 2019, 1:50:16 AM3/18/19
Hi Ben, 

There is a problem with your code (next_walk_section). Take a look here in order to fix it:

You should change the relation with "self" to:

belongs_to :next_walk_section, foreign_key: 'next_walk_section_id', class_name: 'WalkSectionButton'

And be sure that you have a relationship (foreign_key) with the Table itself in your database.



You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Ben Edwards

Mar 18, 2019, 6:11:03 AM3/18/19
to rails_admin
Thansk, yess there is a foregn key.  surly changing it to WalkSectionButton would make it belong to itself.  will try WalkSection.
Reply all
Reply to author
0 new messages