How to fetch multiple documents within a single query? - sanity

I want to fetch multiple pages within a single query.
My code is causing errors
const pagesQuery = groq`{
*[_type == 'homepage']{slug},
*[_type == 'faq']{slug},
*[_type == 'contact']{slug}
}`

Something like this should work.
*[_type in ["homepage", "faq", "contact"]]{slug}

Related

How to filter Sanity posts by category title?

Here what I've done in vision
*[_type == "post" && categories == SOCIAL ]{
_id, title
}
It returned
No documents found in dataset production that match query:
*[_type == "post" && categories == SOCIAL ]{
_id, title
}
You have to format it like so:
*[_type == "post" && categories == "SOCIAL" in categories[]->title]{
title,
slug,
body
}
If nothing shows up then there are no posts associated with that category. Categories are also case sensitive, so make sure your capitalization is right.
*[_type == "post" && "social" in categories[]->title]{
title
}
*[_type == 'post' && category->name == 'Technology']
Can also try this in cases where your categories are not saved as arrays.
What worked for me is instead of searching by the name of the category i searched using the ._ref property of the category.
It would look something like this
*[_type == "post" && categories == categories._ref]

Typo3 9.5 - Custom flexform ordering, wrong backquotes in sql

i have an custom extension, where you can select the different entries at the backend, to show them at the list view. I have a custom sorting at my backend, but the system always sort them Descending.
I implemented an "orderBy" function, which doesnt work, because the system uses wrong backspaces.
My code looks like this:
I call the sort function in my "findByUid($uid)" function like this:
$query->setOrderings($this->orderByKey('uid', $uidArray));
protected function orderByKey($key, $uidlist) {
$order = array();
foreach ($uidlist as $uid) {
//$order["$key=$uid"] = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
$order["$key=$uid"] = "ASC";
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($order);
}
return $order;
}
The result at the sql query is:
ORDER BY `tx_MYEXTENSION_domain_model_FIELD`.`uid=3` DESC
But it must be:
ORDER BY `tx_MYEXTENSION_domain_model_FIELD`.`uid` = 3 DESC
Is there a way to change this?
After a lot of search, I found this solution on an stackoverflow entry:
$ids = explode(',',$this->settings['entries'])
foreach($ids as $key => $id){
$entries[$id] = $this->entriesRepository->findByUid($id);
}
This code snippet has to be intergrated at the controller.
For me its working.

Why does RavenDB perform an OR operation instead of an AND?

Why is there a OR instead of an AND between the SEARCH and the WHERE?
The problem is that the current Lucene query is:
"OrganizationType:Boo ( Name:(Foo) ShortName:(Foo))"
instead of:
"OrganizationType:Boo AND ( Name:(Foo) ShortName:(Foo))"
How can I change that?
RavenQueryStatistics stats;
var organizationQuery = session.Query<Organization>()
.Statistics(out stats)
.Skip((request.Page - 1) * request.PageSize)
.Take(request.PageSize);
if (request.OrganizationType != default(OrganizationType))
{
organizationQuery = organizationQuery.Where(o => o.OrganizationType == request.OrganizationType);
}
if (!string.IsNullOrEmpty(request.Query))
{
organizationQuery = organizationQuery
.Search(c => c.Name, request.Query, escapeQueryOptions: EscapeQueryOptions.AllowPostfixWildcard)
.Search(c => c.ShortName, request.Query, escapeQueryOptions: EscapeQueryOptions.AllowPostfixWildcard);
}
I have added a screenshot with the proposed solution:
To get only documents matching all sub-queries you to have to use Intersect. See the article How to use intersect in the RavenDB documentation.
Because Search is using OR by default. There is an optional parameter that set it to use AND.

Grails: "where" query with optional associations

I'm trying to run a "where" query to find a domain model object that has no association with another domain model object or if it does, that domain model object has a specific property value. Here's my code:
query = Model.where({
other == null || other.something == value
})
def list = query.list()
However, the resulting list only contains objects that match the second part of the OR statement. It contains no results that match the "other == null" part. My guess is that since it's checking a value in the associated object its forcing it to only check entries that actually have this associated object. If that is the case, how do I go about creating this query and actually having it work correctly?
You have to use a LEFT JOIN in order to look for null associations. By default Grails uses inner join which will not be joined for null results. Using withCriteria as below you should get the expected results:
import org.hibernate.criterion.CriteriaSpecification
def results = Model.withCriteria {
other(CriteriaSpecification.LEFT_JOIN){
or{
isNull 'id'
eq 'something', value
}
}
}
UPDATE
I know aliasing is not possible in DetachedCritieria where one would try to specify the join as in createCriteria/withCriteria. There is an existing defect regarding adding the functionality to DetachedCriteria. Just adding the work around for where query as mentioned in defect.
Model.where {
other {
id == null || something == value
}
}.withPopulatedQuery(null, null){ query ->
query.#criteria.subcriteriaList[0].joinType = CriteriaSpecification.LEFT_JOIN
query.list()
}
I would rather use withCriteria instead of the above hack.
this might work:
query = Model.where({
isNull( other ) || other.something == value
})
If that wouldn't work, try something like:
other.id == null || other.something == value
UPDATE:
or with good'ol criteria query:
list = Pack.withCriteria{
or{
isNull 'other'
other{ eq 'something', value }
}
}

How to select items by providing where clause in pivot

This is my code looks like right now :
$result = Category::with(array(
"getProducts",
"getProducts.getBrand",
"getProducts.getImages",
"getProducts.getDetail",
"getProducts.getTax",
"getProducts.getDiscount",
"getProducts.getAttributes" => function($query) use($_temp){
if($_temp != null){
$query->where_in('attributes.id',$_temp);
}
},
"getSlideshow",
"getSlideshow.getItems",
"getAttributeListing",
"getAttributeListing.getAttributes",
"getAttributeListing.getAttributes.productSpecific"
))
->where('id','=', $category_id)
->first();
Yet, It only filters the getProducts.getAttributes items not the 'getProducts' itself. Is there a way that I can get the Products by attributes?
Note: I am using Laravel 3