Use dynamic finders with list of Object IDs

gorm dynamic finders
grails gorm find by id
grails findall in list
grails gorm query
find all by
how to fetch data from database in ruby on rails
grails findall not in list
grails findby is null

With the given class structure

class MyObject {
   Status status;

class Status {
   Integer id;

I want to use dynamic finders to query based on a list of Status ID values. What I want to be able to do is something like this


This does not work though because my list needs to be Status objects. I know I can build a criteria to do this, but I just want to know if there is a way to accomplish this with Dynamic Finders?

You can use the where clause:

MyObject.where { in [1,2,3]}.find()


Dynamic finders don't support aliasing so Criteria (or DetachedCriteria) is the solution to be used.

In case if Status class is a domain entity you could retrieve a list of them (or load their proxies) from the database and then query MyObjects by the status list.

So I see no other appropriate solution but using Criteria in your case.

Querying the Database using GORM Dynamic Finders, git clone Instead of findBy , use findAllBy to return a list of matching instances. types (like Number or String ), but actually contains a list of Game domain objects. { eq 'id', } } // Dynamic finders can be chained onto detached criteria to narrow � With dynamic finders, you can find records where a property is tested against items from a provided list: use the InList comparator. Here are two examples. The first finds all of the Game records that match a list of String game names, while the second example finds all Match records that track the game play of the games listed.

You can still accomplish this using the dynamic finder.

def statuses = [1, 2, 3].collect { Status.load(it) }

load() will create a proxy for you that won't require retrieving the instance from the database as long as you don't access any properties other than id.

7 Object Relational Mapping (GORM) 2.4.5, For example using the list method on the Content super class will return all To get around this problem you can use the static lock method that takes an id just like GORM supports a number of powerful ways to query from dynamic finders, � Locate and select the 'textboxD18284e6' object either in the 'Aliases' tree or in the 'Mapped Objects' tree. To the right, you'll see the identification properties and values TC used to map the object. You should see the 'ObjectIdentifier' property which has the 'D18284e6' value. Replace the value with '*' (without quotation marks).

You can use this.

List<Integer > statuses = [1, 2, 3] MyObject.findAllByStatusInList(statuses)

Active Record Query Interface, All of the following models uses id as the primary key, unless specified otherwise. Active Record lets you retrieve a single object using three different ways. You can specify an exclamation point (!) on the end of the dynamic finders to get � Instead of object, you could use the keyword dynamic, but an even better solution would be to use some static type (if possible). You can use dynamic like a dictionary, the added link will provide you with some great examples.

Active Record Query Interface — Ruby on Rails Guides, How to use dynamic finder methods. How to use method To retrieve objects from the database, Active Record provides several finder methods. Each finder� by Hassan Djirdeh An introduction to dynamic list rendering in Vue.js List rendering is one of the most commonly used practices in front-end web development. Dynamic list rendering is often used to present a series of similarly grouped information in a concise and friendly format to the user. In almost every web application we use, we can see lists of content in numerous areas of the app. In How and When to Use Various GORM Querying , Grails Object Relational Mapper (GORM) is a really nice ORM. For example, we can use dynamic finders to get a list of products filtered in different ways: manufactur2_ ON product_al1_.manufacturer_id =� Important. Objects that are not schema-scoped, such as DDL triggers, cannot be queried by using OBJECT_ID. For objects that are not found in the sys.objects catalog view, obtain the object identification numbers by querying the appropriate catalog view.

Implementing a Custom Finder Method Using Dynamic Query , Once you've defined your custom finder method, you can use the Dynamic Query a dynamic query, which returns results (a list of guestbook Entry objects) if all The first query retrieves a list of guestbook IDs corresponding to guestbook� If you use a dynamic object, you can reference the id attribute as Dynamic objects also provide convenient access to dynamic languages such as IronPython and IronRuby. You can use a dynamic object to refer to a dynamic script that is interpreted at run time. You reference a dynamic object by using late binding.

  • Thanks for that, but that is essentially a criteria built query which I mentioned already know about. I am specifically looking for a way to do this with the dynamic finder API. If it is not possible then please note that in your answer.
  • @RaymondHolguin updated the answer. Why are you avoiding Criteria?
  • Do the dynamic finders query always by the object ID? Meaning if I have overloaded the equals() or implemented Comparable does that have any effect if load() only pulls the id?