I have the following code:
class Item < ActiveRecord::Base belongs_to :user has_many :transactions #scope :active, lambda?? end class Transaction < ActiveRecord::Base belongs_to :user belongs_to :item scope :active, where("status = 0") end class User < ActiveRecord::Base has_many :items has_many :transactions end
I want to create a region in a model element to retrieve only records with active transactions, for example:
User.find(1).items.active
I have found the answer. it will be like this:
scope :active, joins(:transactions) Transaction.active
The answer was here: http://asciicasts.com/episodes/215-advanced-queries-in-rails-3
Source: https://habr.com/ru/post/1383184/More articles:Is geometry represented outside OpenGL ES Frustum? - opengl-esLook for the cheapest way to use std :: wstring with NSLog - c ++CUDA - limit the number of SMs used - cWindows Phone ApplicationBar BackgroundColor Property Property XamlParseException - windows-phone-7JavaScript - requires the function of loading external JS files - javascriptPhp + Mysql: full text and grant search without server-side support - phpScrolling ListView with data - javaHow to download the xsd file, which is stored in the / WEB-INF folder - javaFilling a non-closed PathGeometry to the bottom - wpfhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1383189/how-to-grant-read-access-to-all-files-in-a-folder-and-subfolders-using-c&usg=ALkJrhiekc8TIAS-AnKO4_WOKZyhgeAn1wAll Articles