검색결과 리스트
model에 해당되는 글 2건
- 2016.03.21 [Rails] migration 마이그레이션 파일 생성하기
- 2016.02.18 [Rails]model에서의 not like 동작 하게 하기.
모델에서 데이터를 추출할 때 쿼리에서의 not like를 구현하고 싶을때.
@perms = PaperTrail::Version.where(item_type: "Device").where.not(object_changes: ["%last_qc%"]).order('created_at DESC').limit(50)
- 이렇게 했을 경우에 쿼리는 다음과 같이 나오게 된다.
select * from versions where item_type = "device" and ( object_changes != '%last_qc%') order by created_at DESC limit 50
이 것의 의미는 "%last_qc%"를 비교하는 쿼리가 된다. 즉 "" 안에 있는 %가 like가 아닌 % 문자열로 인식하게 된다.
PaperTrail::Version.where(item_type: "Device").where.not("object_changes LIKE?","%last_qc%").order('created_at DESC').limit(50)
> 컬럼명 안에 "LIKE?"를 넣어서 not이 아닌 not like로 인식하는 쿼리가 되게 한다.
select * from versions where item_type = "device" and ( not(object_changes LIKE '%last_qc%')) order by created_at DESC limit 50
RECENT COMMENT