Questions tagged [dynamic-finders]
49 questions
2
votes
3 answers
Dynamic bang finders in Rails 4
Rails 4 is getting rid of dynamic finders, so
User.find_by_hash(hash)
becomes
User.where(hash: hash) # .first
Okay, not a big deal. But what is the best way to deal do with dynamic bang finders like User.find_by_hash!(hash) since there is no…

firedev
- 20,898
- 20
- 64
- 94
1
vote
1 answer
How to use ActiveRecord Find dynamically by passing in a Hash of params?
Is there a way to use find_or_initialize_by but pass it a hash of params and have it search on those?
I have a form that allows a user to create a Car, and specify different components for that Car (Car.engine_type, Car.model, etc). The user could…

beeudoublez
- 1,222
- 1
- 12
- 27
1
vote
3 answers
Conditional Dynamic finder in grails
so i require something like the dynamic finder should change as per the condition, let me explain by code what i mean
the below code find all employee by status and lastdateattended
def employee =…
user5441083
1
vote
0 answers
Grails Dynamic Finder .findAllById(id) vs .findById(id) with new object in same transaction
I'm experiencing strange behaviour between
.findAllById(id)
.findById(id)
I'm creating a new domain class and then later in the same transaction I'm looking up that same object with a dynamic finder. When using .findAllById(newObjectId) it finds…

TimJ
- 426
- 4
- 12
1
vote
2 answers
Grails: findAllWhere sort/max/offset operator don't work
I know that dyanmic finders in grails only support 2 parameters
eg.
artifacts = Artifact.findAllByDocumentAndArtifactType(document,artifactType,[max:limit, offset:startIndex]);
So to use more than 3 arguments I found this example and it works.…

krs8785
- 1,097
- 2
- 14
- 24
1
vote
2 answers
Rails 4 Active Record finder method
I have a Rails 3 Active Record finder method and i am trying update it to rails 4 patten.
In Rails 3, my code looked like this
StripeEvent.setup do
subscribe 'customer.subscription.deleted' do |event|
user =…

Benjamin
- 2,108
- 2
- 26
- 46
1
vote
2 answers
Can a Grails dynamic finder be broken by application code?
There is some code in the project I'm working on where a dynamic finder behaves differently in one code branch than it does in another.
This line of code returns all my advertisers (there are 8 of them), regardless of which branch I'm…

Samo
- 8,202
- 13
- 58
- 95
1
vote
1 answer
Filtering a collection with offset in grails
I'm trying to filter a collection in grails with findAll so I only get the instances with a certain value in his field "estado".
I have something like this:
trabajos.findAll({it.estado.equals( "Pago")})
The problem is I dont know how to paginate…

user1485182
- 41
- 1
- 1
- 11
1
vote
1 answer
Spring Data JPA finder for dynamic fields as Map
My requirement is to have few custom fields in the domain objects. These fields may vary as per the clients.
We are using Spring Data JPA to execute finders. Spring data implicitly provides finders for static fields of the domain and can also handle…

bornleo
- 478
- 3
- 8
1
vote
3 answers
Rails: find and find_by return strange # in model, but not in rails console
Weird problem I've been stuck on for several hours now:
I'm writing a simple user login using Rails 3, where a user logs in with their email and password. In my User model, I'm trying to find the correct User object by their email, then continue to…

corbin
- 2,797
- 3
- 18
- 17
1
vote
1 answer
@Mock domain objects in unit testing in grails listOrderBy dynamic finder throws an exception
I am writing a unit test for a grails controller. Here is a snippet of the code:
@TestFor(MyController)
@Mock([MyDomain])
class MyControllerTests {
void testController() {
...
...
}
}
Here is how the domain object looks…

DaHoopster
- 572
- 4
- 18
1
vote
0 answers
Rails Dynamic Finders Return nil
Using Ruby on Rails - sqlite3, rails 3.2.2, ruby 1.9.3p125 (on windows XP)
Having the record in the db:
Shop.find(123) - returns the shop
Shop.where(:id => 123) - returns the shop
but
Shop.find_by_id(123) returns nil
Shop.find_by_name("some_name")…

Yaniv Preiss
- 239
- 2
- 7
1
vote
1 answer
Grails SQL Error on run
I am trying to make a simple web app for a school project in Grails. I can access the server, save, delete, and everything else, but whenever I first run the app I am getting masses of SQL errors thrown at me. I am using Grails 2.0.3 and…

Howes
- 799
- 1
- 7
- 15
0
votes
1 answer
Dynamic finders return a new object different from anyone in the has_many collection?
I'm trying to find a object from the has_many collection by dynamic-finders, and then update the attribute of the returned object. But I really don't know when the updated attribute value will be synchronized to the has_many collection. Because I…

Joey Zhang
- 3
- 1
0
votes
1 answer
How can I make a transient attribute available in dynamic finders?
I have a model X with an attribute thedate of type datetime.
What is the slickest way to make thedate's year available for dynamic finders?
Examples:
X.find_by_year(2012)
X.find_by_location_and_year('here', 2012)
X.find_by_year_and_name(2012,…

user569825
- 2,369
- 1
- 25
- 45