Skip to main content

Combining Multiple Querying Methods

You can also use query with multiple methods based on your needs, by combining the previous methods like those examples :

Examples :​

List<Product> twoProductsFromThirdPage = await YouCan.instance.products.pagination(3).limit(2).all();

List<Product> firstProductWithTitleStartingWithA = await YouCan.instance.products.search("A").limit(1).all();

List<Product> threeProductsFromPage5WithTitleStartingWithB = await YouCan.instance.products.pagination(5).search("B").limit(3).all();

List<Product> fourProductsOfOneCategory = await YouCan.instance.products.category("CATEGORY ID").limit(4).all();

Keep In Mind​

Query Methods Order Don't Matter.​

Before calling tha all() on your query code, the order of the query methods doesn't really matter, those following query are the same, and will return the same result:

List<Product> firstQuery = await YouCan.instance.products.pagination(13).search("B").limit(3).all();

List<Product> secondQuery = await YouCan.instance.products.search("B").limit(3).pagination(13).all();

Calling Same Query Methods Will Take The Last One Only.​

Trying to call a querying method multiples times on the same query code will takes only the last method and ignore the previous ones

final example5 = YouCan.instance.products.pagination(5).pagination(10).pagination(100);

the example above will consider the last pagination() and return a query on the page 100, and it will not throw an error for previous ones, it will just ignore them.

Limitations​

Well, queries that combines search() and pagination() are not allowed, and will throw an error if they are combined.