Answer the question
In order to leave comments, you need to log in
How to rewrite query in ORM Ruby on Rails?
Hello! Help with links in models
There are 3 tables: Clients, Contacts, Calls
The Calls table has both ClinetId and ContactId
There is a request
SELECT `calls`.*
FROM `calls` WHERE `calls`.`CallContragent` = '130350'
OR `calls`.`CallContact`
IN ('74031', '74032', '74214', '74221', '74222', '74243', '74256', '74273', '74293', '74294', '74296', '74323', '74327', '74535', '74536')
Answer the question
In order to leave comments, you need to log in
your request does not need links, like this
Call.where('CallContragent' => 123).or.where('CallContact' => [123, 123, 123]) # rails 5
Call.where('CallContragent = ? OR CallContact IN ?', 123, [123, 123, 123]) # rails 4
belongs_to :client
belongs_to :contact
has_many :calls
has_many :contacts, through: :calls
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question