Re: [Rails-core] Method to find inside of relation

2014-11-24 Thread Matt Jones
On Nov 22, 2014, at 5:03 PM, Sunny Juneja jr.su...@gmail.com wrote: Hey everyone, I've obviously done a bad job of explaining this :). Let me try to elaborate. Suppose I've ran xyz = Model.where(attribute: true) A SQL query is created and executed. The results are saved to xyz as an

Re: [Rails-core] Method to find inside of relation

2014-11-22 Thread Sunny Juneja
Hey everyone, I've obviously done a bad job of explaining this :). Let me try to elaborate. Suppose I've ran xyz = Model.where(attribute: true) A SQL query is created and executed. The results are saved to xyz as an ActiveRecord_Relation. The query looks something like this: SELECT models.*

Re: [Rails-core] Method to find inside of relation

2014-11-16 Thread Matt Jones
On Nov 14, 2014, at 4:05 PM, Sunny Juneja jr.su...@gmail.com wrote: Hey, I ran into this problem fairly recently. I needed to get a large number of records and search them over and over again on different attributes. I found myself writing code that looked a lot like this. records =

[Rails-core] Method to find inside of relation

2014-11-14 Thread Sunny Juneja
Hey, I ran into this problem fairly recently. I needed to get a large number of records and search them over and over again on different attributes. I found myself writing code that looked a lot like this. records = Model.where(...) records.select { |r| r.attribute1 == attribute1 r.attribute2

Re: [Rails-core] Method to find inside of relation

2014-11-14 Thread Carlos Antonio da Silva
You should be able to use find_by and pass in a hash with attributes and respective values to find a record. Please take a look at the docs for find_by on the api guides. Carlos Antonio da Silva - via celular On Nov 14, 2014 7:44 PM, Sunny Juneja jr.su...@gmail.com wrote: Hey, I ran into this