query-builder

Laravel Queries: Adding custom feature like Soft Deletes

可紊 提交于 2019-12-13 05:06:04
问题 All of my tables have a column called isTest . What I want is to be able to set a switch so that my code will either include all records in my queries or [more importantly] exclude all records where isTest is true. I imagine the code will work similarly to Soft Deletes and include sql code similar to: AND (isTest != TRUE) to SQL generated by Eloquent and the Query Builder. I am not really familiar with Eloquent events, but I have found this question which might be the right place to start,

MongoDB QueryBuilder query creation using same field

ε祈祈猫儿з 提交于 2019-12-13 04:23:40
问题 I have a simple mongoDB query: var qry = QueryBuilder.start qry.and("website").exists(true) qry.and("website").notEquals(null) qry.and("_id").in(loc_ids) website is a field in my collection, and loc_ids are a list of OIDs to each record... The cursor does not result in any records returned from the query? Seems like the problem is the "website" : { "$exists" : true , "$ne" : ""}... So my question is this a valid query creation: var qry = QueryBuilder.start qry.and("website").exists(true) qry

Symfony 4, doctrine, getResult and getArrayResult and getScalarResult return same structure results

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 04:01:29
问题 From symfony 4, I create a sample repository class. From this class, I created a method for get the list of all email's users. I would like get a array structure like this : array( "email1", "email2", "email3", ... ) But with 'getResult' I get a multidimensional array. Then, I tested with getArrayResult and getScalarResult and I obtain each time exactly the same array structure result ! Below, my Service Class : <?php class UserRepository extends ServiceEntityRepository { public function _

AEM: How to find the nodes with property name “customProp” and empty property value, using query builder?

别等时光非礼了梦想. 提交于 2019-12-13 02:06:08
问题 There are nodes which have properties but no values. I am trying to avoid those nodes in query builder using, path=/content/ type=cq:Page 2_property=jcr:content/customProp 2_property.operation=exists 3_property=jcr:content/customProp 3_property.operation=unequals 3_property.value= But the empty value condition (3_property) is being ignored. How this can be achieved? 回答1: I had the issue to search for all occurrence of a propertiy with no value. I constructed the following SQL2 Query: SELECT *

Doctrine2 fetching rows that have manyToMany association by QueryBuilder

余生颓废 提交于 2019-12-12 13:29:48
问题 everyone. I have 2 entities City and POI. Mapping looks like this: class City { /** * @ORM\ManyToMany(targetEntity="POI", mappedBy="cities") * @ORM\OrderBy({"position" = "ASC"}) */ protected $pois; and class POI { /** * @ORM\ManyToMany(targetEntity="City", inversedBy="pois") * @ORM\JoinTable(name="poi_cities") */ protected $cities; I would like to fetch all POIs that have at least 1 association with some City using QueryBuilder. I should probably use exists() function but I don't quiet know

paginator call on query builder does not return paginator object in laravel 4 (in a specific case)

ぃ、小莉子 提交于 2019-12-12 05:18:44
问题 Problem: Query builder: $r = DB::table('someTable'); $r->where(....) $r->paginate(30, array(....)) return $r; Now calling a get_class() on $r gives Illuminate\Database\Query\Builder But after opening up vendor/laravel/framework/src/Illuminate/Database/Query/builder.php , i saw this, public function paginate($perPage = 15, $columns = array('*')) { $paginator = $this->connection->getPaginator(); if (isset($this->groups)) { return $this->groupedPaginate($paginator, $perPage, $columns); } else {

Hibernate QueryBuilder how to mimic 'like' query

瘦欲@ 提交于 2019-12-12 03:57:41
问题 I am learning this API now. I have some code as below, but it does an exact match instead of a 'like'. So when I have a String JMeter , and I use Meter , it does not bring it back in the search result but it should. Any help greatly appreciated SearchManager searchManager = Search.getSearchManager(listingIndex); QueryBuilder qb = searchManager.buildQueryBuilderForClass(ListingIndexEntry.class).get(); Query q = qb.keyword().onField("title").matching(title).createQuery(); Thank you Karthik 回答1:

How to insert Json into cassandra using API, QueryBuilder and batch

此生再无相见时 提交于 2019-12-12 03:46:00
问题 I see that all examples for JSON uses the query as string like String cqlStatement = "INSERT INTO users JSON '{\"id\":888 , \"age\":21 ,\"state\":\"TX\"}'"; but I want to use QueryBuilder, since I would like to insert in batch. Thanks 回答1: Use Insert.json() method Inserts the provided object, using the INSERT INTO ... JSON syntax introduced in Cassandra 2.2. Example : QueryBuilder.insertInto("my_data").json("{\"id\": 1, \"value\": \"This is a test\"}"); Note : Any columns which are omitted

Symfony QueryBuilder returning MongoDB cursor instead of objects array

蓝咒 提交于 2019-12-12 03:36:49
问题 I am trying to build a custom querying function returning MongoDB documents corresponding to some filters. I have created this function into a specific repository for my document User : namespace LogAnalyzer\CoreBundle\Repository; use Doctrine\ODM\MongoDB\DocumentRepository; class UserRepository extends DocumentRepository { public function getUserTemp($clauses = null) { /* Create query */ $query = $this -> createQueryBuilder(); /* Add clauses */ if($clauses) { if(isset($clauses['id'])) $query

How to select only those records that have at least one associated record?

痞子三分冷 提交于 2019-12-12 03:24:09
问题 I have the following associations: Orders belongsTo Sites I execute the following query: $sites = $this->Sites->find('all') ->select(['id', 'name']) ->contain([ 'Users' => function ($q) { return $q->select(['id', 'owner_id', 'firstname', 'lastname']); }, 'Orders' => function ($q) { return $q->where(['status >' => 0]); }, 'Orders.Agplans' ]) ->matching('Users', function ($q) use($owner_id) { return $q->where([ 'Users.owner_id' => $owner_id ]); }) ->all(); But most of the sites have no orders