주어진 다음의 코드 : user_decorator.rb Refinery::User.class_eval do
has_many :employees, :class_name => 'Refinery::Employee'
scope :active_employees,
lambda {
joins(:employees).merge(:
를로드하는 경우 데이터베이스를 치는 country = Country.include(:cities).find(id)
그러나 때 나는 실행 : country.cities.big
그것은이 쿼리와 DB에 타격을한다 : SELECT * FROM cities where country_id = 1 AND population > 1000000
잘 작동하지만,
질문에 똑바로. @issue_books.taken(params[:id])
은 내가 ArgumentError: wrong number of arguments (1 for 0) 오류 : 이제 때마다 나는이 쿼리를 실행 scope :taken, lambda { |book_id| where(returned: false).where(book_id: book_id
나는 class Foo
scope :test1, ...
scope :test2, ...
scope :test3, ...
그리고 함수 추천라는 이름의 범위가있는 경우 변수가 문자열 def x(variable)
end
("TEST1", "TEST2"또는 "TEST3") 변수의 값만 알면 명명 된 범위에 어떻게 액세스 할 수 있습니까? 당신은
나는 레일에 익숙하지 않으므로 인내심을 부탁드립니다.이 class Producer
has_many :clients
end
class Client
belongs_to :producer
has_many :products
end
class Product
belongs_to :client
belongs_to
class << self 컨텍스트 내에서 범위를 동적으로 할당하려면 어떻게해야합니까? class Partner < ActiveRecord::Base
STATUS = {
pending: 0, # 0 account has a pending billing request (but is not yet open)
active: 1, #
with_category와 simple_search의 두 가지 범위가 있습니다. 각각은 개별적으로 잘 작동하지만 함께하면 원하는 것을 정확히 얻을 수 없습니다. product.rb has_many :categorizations, :dependent => :destroy
has_many :categories, :through => :categorizatio
사용자 테이블에 이름 필드가 있습니다. 일부 레코드는 이름이고 일부는 전자 메일입니다. 나도 알아, 나쁜 접근. 그건 제쳐두고. 전자 메일 레코드 만 반환하는 명명 된 범위를 작성하고 싶습니다. 이 쿼리를 수행하는 쿼리를 적용하려고 시도했지만 실패했습니다. MYSQL : SELECT NAME
FROM USER
WHERE NAME LIKE '%@%.%'
나는 역할이있는 사용자 인 admins에 대한 스코프를 정의하는 user.rb에 대한 모델을 가지고 있습니다. 권한 테이블을 통한 관리자 has_many :permissions
has_many :roles, :through => :permissions
범위는 다음과 같이 작동 scope :admins, joins(:permissions).merge(P