All threads / Namespace rails belongs_to

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Namespace rails belongs_to

Tiago Batista Xavier asked in Rails

I have the following configuration

module Account
class Permission <ApplicationRecord
end
end

module Account
class GroupPermission < ApplicationRecord
belongs_to: permission
end
end

Table: account_group_users
account_users_id bigint,
account_groups_id bigint,
Table: account_group_permissions
account_permissions_id bigint,
account_groups_id bigint,
When I try to access the Account :: GroupPermission instance and through it access Account :: Permission returns nil.

Only works if I specify class_name:

Hi Tiago, is this a typo?
belongs_to: permission
It should be belongs_to :permission

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.