Я пытаюсь определить область действия в моей модели учетной записи, но она не работает. Вот мой код:
class Account < ActiveRecord::Base
has_many :organizations
scope :primary, joins(:organizations).where('organizations.primary = ?', true)
accepts_nested_attributes_for :organizations
end
class Organization < ActiveRecord::Base
belongs_to :account
has_many :locations
accepts_nested_attributes_for :locations
end
С консоли я попробовал следующую команду:
Account.primary.first
Но я получаю следующую ошибку:
ActiveRecord::StatementInvalid: SQLLite3::SQLException: near "primary":
syntax error: SELECT "accounts".* FROM "accounts" INNER JOIN "organizations" ON
"organizations"."account_id" = "accounts"."id" WHERE (organizations.primary = 't')
LIMIT 1
Я думаю, что имя «основной» может быть причиной проблемы. Когда я переименовал область видимости в «важный» и попытался это получить:
NoMethodError: undefined method 'important' for #<Class:0x1f4a900>
Если кто-нибудь может помочь, я буду очень признателен.