Questions tagged [query-builder]

A query-builder is a set of classes and methods that is able to programmatically build queries.

query-builder
Filter by
Sorted by
Tagged with
0 votes
1 answer
121 views

i want to get only 3 blog of per category. but code return me all blogs of per category laravel

i want to get only 3 blog of per category. but code return me all blogs of per category laravel example i have 2 category (category 1 haves 10 blogs and category 2 haves 7 blog). now i want only 3 ...
Gagan Dev's user avatar
-1 votes
2 answers
614 views

How to get records with multiple where in many to many relationship?

I'm working on a Laravel version 9 project. At first, I explain the tables and relationships. There are 3 tables: advertisements, advertisement_tags and the pivot table advertisement_advertisement_tag....
Rayan's user avatar
  • 313
1 vote
1 answer
878 views

After common Typeorm query builder instance, where clause not working

I create QueryBuilder to fetch my relation data. So in my case, I need to validate some of my get req params before the index. So in this case I created a common QueryBuilder instance like this. // ...
Zenixo's user avatar
  • 799
0 votes
2 answers
412 views

Do not retrieve all columns with Elastic search query

I have an Elastic search query and I would like to retrieve a certain column, not all. I make my request in java with BoolQUEryBuilder which gives: BoolQueryBuilder query = boolQuery(); query.must(...
EleXorZ's user avatar
  • 47
0 votes
2 answers
585 views

Doctrine QueryBuilder - add PARTITION selection in clause FROM

I have a table "actions" with partitions PARTITION BY RANGE (MONTH(`created_at`)) ( PARTITION `m1` VALUES LESS THAN (2), PARTITION `m2` VALUES LESS THAN (3), ...
user2007024's user avatar
0 votes
1 answer
1k views

Use parameter with DB::raw in Laravel 9

I have this SQL query which returns all employees based on selected date : SELECT employees.id as employee_id ,employees_salaries.*,CONCAT(first_name,' ',second_name,' ',third_name) as fullname FROM ...
Yu_Jain's user avatar
  • 151
3 votes
3 answers
1k views

How to change Eloquent Builder's connection?

I have a Eloquent Builder and two database connections(mysql_server1, mysql_server2) as below: $builder = User::query(); $builder->where('age', '>', 20); $builder->with('orders'); // ...
Hamed Kamrava's user avatar
0 votes
1 answer
62 views

How to write this SQL query with Yii Query Builder

I have this SQL query which is doing what I want: SELECT `Table1`.* FROM `Table1` LEFT JOIN `Table2` ON `Table1`.`idTable2` = `Table2`.`id` WHERE (`Table1`.`idOwner`=156 AND `Table2`.`enabled`=1 AND ...
Carlos's user avatar
  • 3
0 votes
2 answers
2k views

unable to select alias in getMany Typeorm

I'm using TypeORM(mySQL) for my Nestjs App. I want to change the column name on select using querybuilder. but it's not working. const order = await this.connection .createQueryBuilder(Orders,&...
zulqarnain's user avatar
  • 1,596
0 votes
0 answers
28 views

Laravel query builder not delete the data but when convert into raw query it works [duplicate]

Here is my code i just want to remove duplicate rows but it not execute DB::table('competition_participants as t1') ->join('competition_participants as t2', 't1.id', '<', 't2.id') ->...
Pallavi Biwal's user avatar
-1 votes
1 answer
350 views

Laravel Paginate by column value

I would like to find out if the following is possible with laravel query builder. Currently using Laravel 9. I want to create pagination, but instead if supplying the count ->paginate(20) as per ...
Alex Coetzee's user avatar
0 votes
1 answer
316 views

i want to get all user data with data on behalf of batch_id

i want to get data in instructor dashboard on the behalf of batches assigned to them from order product table where if user buy single course then we get batch id and if user buy package(package ...
Programming Evolution's user avatar
1 vote
1 answer
117 views

Access level to Illuminate\Database\Query\JoinClause::forSubQuery() must be public laravel error?

I have a simple decent query in my laravel application which is nothing but a left join $spDetails = ServiceProvider::from(‘ipay_app.service_providers as sp’) ->leftJoin(‘ipay_app_bbps....
Rohannn Singh's user avatar
3 votes
1 answer
2k views

Sorts on relationships with Spaties QueryBuilder

Having the following QueryBuilder statement how can I define sorts on related models columns? $members = QueryBuilder::for(Member::class) ->allowedIncludes('user.name', 'association', '...
fefe's user avatar
  • 8,955
0 votes
1 answer
87 views

Codeigniter 4 - Getting result from database issue

I'm new to codeigniter 4 and having some issues retrieving data from my database. In my controller, I have: $partno = model(Ecart_model::class)->getPartno($productid); echo json_encode($...
programmingnewb's user avatar
0 votes
1 answer
84 views

Laravel only join linked model if parent has boolean switch

I'm using Laravel 8 and have two models: Domain and Certificate. A domain can have one certificate. On my domain model, I have a boolean column called certificate_checks_enabled, and where I'm ...
Ryan H's user avatar
  • 2,742
0 votes
1 answer
86 views

Laravel Query Builder How to Context Not Conditions

I have a laravel query PasswordMovement::whereId($id)->update(['active' => '!active']); my active field converts to 0 if it is 1. but if it is 0, it doesn't convert to 1? Laravel Query Builder ...
poison pawn's user avatar
0 votes
2 answers
1k views

Laravel how to addSelect all total counts on a single table each row

i am trying to build a single query but something is wrong. i want to write a code that each row have a all total count on a one table. i will describe first i will query the total counts : $count = ...
Ray  Paras's user avatar
  • 157
0 votes
0 answers
580 views

How Can I compare table column by convert it first in postgresql + typeorm

I am beginner in Backend technology and I am developing one query in Typeorm QueryBuilder + PostgreSQL. My query is look like this : But I can't convert my timestamp into following format. Can anyone ...
Mayur Kukadiya's user avatar
0 votes
1 answer
406 views

Each letter typed in input is causing rerendering component in React Querybuilder

I'm using react query builder with MaterialUI and I found a bug in ValueEditor where each typed letter in TextField is causing rerendering. Here is codesanbox example of same thing using regular input ...
HardRock's user avatar
  • 989
0 votes
1 answer
125 views

Problem optimization with symfony 6 / doctrine : too many querys

The project is develop with symfony 6.0.8. I have 2 entitys : utilisateur (user) & compte_client (customer) - link by OneToOne relation because an user may be not a customer. A user can be : an ...
EdoDev's user avatar
  • 1
-1 votes
2 answers
458 views

Return ORM object and convert SQL to Doctrine QueryBuilder syntax

I'm creating a function that should return an array of User ORM object. The function should run a query to the DB and return the users where the users' contact persons has 1 company (not more or less)....
Mats K's user avatar
  • 1
0 votes
1 answer
2k views

how to get last query in codeigniter 4? [duplicate]

This is my current code: public function index() { $tbl = 'm_trx'; $db = \Config\Database::connect(); $builder = $db->table($tbl); $data = []; $cols = "{$tbl}.*";...
dapidmini's user avatar
  • 1,548
0 votes
1 answer
63 views

Filter in formbuilder with querybuilder (Symfony)

p is profile and u is user. Each user has one or more profiles. I want to filter one profile from each user who have more than 10 points. But I want to keep only one profile of each user that meets ...
Sank's user avatar
  • 1
2 votes
1 answer
94 views

is there a tool or any quick way to extract db tables automatically from my php codes?

I recently started to re-engineer a PHP-mysql project which was created about 7 years ago. I have only php and html codes and no mysql database or any document which shows the database structures. Is ...
MAli Fahimi's user avatar
1 vote
2 answers
2k views

Laravel: Which one is better to "reset" a table: ->truncate() or ->delete()?

I'm using ->truncate() to delete the data, but DB::rollback() in a try catch doesn't executed when I use it. Meanwhile the ->delete() is executed by DB::rollback(), but with it my auto increment ...
Aditya Pratama's user avatar
0 votes
1 answer
668 views

Order multiple entities by date with query-builder (Symfony)

I was wondering if I could possibly order multiple entities by their date of creation with the query builder in Symfony. This is my query: public function findContributions(Association $association) ...
Nejma A's user avatar
0 votes
1 answer
321 views

How to compare Query conditions from a BelongsToMany association in CakePHP 4.x?

I have a working Posts, Categories and Tags relationship. (Posts BelongsTo Categories and BelongsToMany Tags.) They work just fine at my view and index actions with no issue. Now, for a simple "...
Damian Fraustro's user avatar
2 votes
1 answer
477 views

Laravel Query builder where() for when Product has to have multiple tags (with product_tags pivot table many-to-many)

I am new to Laravel and I got a complicated query to build. I managed to sort it except for when a user asks for multiple tags (tags = 1, 2, 3). Product shown has to have all tags that the user asks (...
Roman123's user avatar
0 votes
0 answers
485 views

Laravel update query error using query builder with comma separeted values

I am getting the below error in the laravel controller when I update 4 columns with comma-separated values without quotes which are coming from the request Request payload: column1 : one,two,three ...
Kamesh K's user avatar
0 votes
1 answer
1k views

Typeorm query on ManyToMany relations

I'm trying to query over the table products to find, Certain products that have "at least" Category "Food", "Cold". I hope someone can give me a hand to be able to query ...
A-Symphony's user avatar
0 votes
2 answers
66 views

Query combination in Laravel

i am facing a problem where my function have a request from the frontend for sorting the data. So i need to add some condition to my query. I tried to do this way. $hawker = Hawker_location::...
Lalat Putih's user avatar
-1 votes
1 answer
1k views

PostgreSQL / TypeORM: search array in array column - return only the highest arrays' intersection

let's say we have 2 edges in a graph, each of them has many events observed on them, each event has one or several tags associated to them: Let's say the first edge had 8 events with these tags: ABC ...
justdvl's user avatar
  • 754
0 votes
0 answers
1k views

How to query data from subquery table in typeorm

Here is what I want: select * from ( select requester_id, CASE WHEN requester_id = 'f791283d-43fd-484c-b11b-3360f436437c' THEN addressee_id WHEN addressee_id = 'f791283d-43fd-484c-...
Alopwer's user avatar
  • 640
0 votes
0 answers
119 views

How to avoid conflict collection model in query builder union in laravel

I have 2 models Test and Exam; table related to these model have the same columns: id, name, point; i want to retrieve the 2 data by using union: $test = Test::where('point', '>', 10); $exam = Exam:...
Michel Gisenaël's user avatar
0 votes
1 answer
650 views

Laravel / Postgres - How to group by one column and select multiple columns?

I have FOR EXAMPLE laravel query builder: DB::table('users')->select('name', 'phone', 'age')->groupBy('age')->... How to do this query work? The problem is that postgres can't group only by ...
as lan's user avatar
  • 37
1 vote
2 answers
2k views

Laravel query builder select all except specific column

I have 2 tables with the same columns except the second table have one more column, this column is foreign key of the first; what i want is to make union query;but for union the column must the same; ...
Michel Gisenaël's user avatar
1 vote
1 answer
181 views

How to build query from SQL by Doctrine QueryBuilder?

I'm new in Doctrine ORM, and I need help with building QueryBuilder command. I have a SQL command and I need covert to QueryBuilder. $qb = $this->entityManager->createQueryBuilder(); The SQL is: ...
Michwuanquana's user avatar
0 votes
1 answer
82 views

Codeigniter changes with `count_all_results`

So... it appears as if overnight, SOME-thing has changed with either the Codeigniter 4 framework or PHP in general, as my website is now down - and it seems to be centred around my call to a ...
seixwebdev's user avatar
0 votes
0 answers
320 views

Full text seach in Doctrine using query builder with no result hits

Specs: Symfony v5.3.16 SQL Server 2017 Doctrine Bundle v2.4.4 Doctrine ORM v2.9.6 I've got a problem with full text search for SQL Server using Doctrine's query builder. I'm trying to use it with ...
Chomik's user avatar
  • 3
1 vote
1 answer
44 views

Is there any benefit in using parameters for query parameters that dont change?

I am writing methods in PHP classes that use QueryBuilder for the DBAL (Doctrine) ORM. One of the thing I like about this is that we can easily use parameters in the SQL that is generated. However, as ...
UnKulMunki's user avatar
1 vote
0 answers
222 views

How to save a Many-To-Many relationship with custom properties with typeORM Query Builder?

I need to create a many-to-many relationship between the tables organisation and user, where each user can have a role (admin, follower...) in the organisation. I have : Organization @Entity('...
Léalbatroz's user avatar
2 votes
1 answer
293 views

Laravel efficient way to remove X records if there are duplicates

I'm trying to write a query to be able to find duplicate records based on a column called hash and remove all but the 5 newest records, I figured I could use the limit method to limit the number of ...
Ryan H's user avatar
  • 2,742
0 votes
0 answers
226 views

AEM Site search query builder URL is not returning a different json

Am using AEM Site search component from core components. query builder URL is not returning a different json. Once after searching with a text, am getting a json. Thereafter doing any search with new ...
Saravanan's user avatar
0 votes
1 answer
200 views

How to fetch SQL Server procedure returned value?

I'm trying to execute the procedure down below using Laravel query builder and the result always empty array, SQL Procedure CREATE FUNCTION [dbo].[FConvTxtUnt] ( -- Add the parameters for the ...
Esso's user avatar
  • 23
0 votes
1 answer
1k views

How I can convert the following SQL query to TypeORM QueryBuilder

I've the following SQL query: SELECT fc.cli_codigo_cod, dg.dog_json_vrh FROM fae_documento_generado dg JOIN fae_cliente fc ON dg.cli_id_idt=fc.cli_id_idt WHERE fc.cli_codigo_cod IN('13312','150501') ...
Edycar Reyes's user avatar
0 votes
2 answers
2k views

Limit query results in laravel

I am trying to limit the results of this query: $gallery = Event::with('EventsMedia')->orderBy('start', 'desc')->get(); currently it shows all the events with their images. What i want is to ...
Convert.ToInt32's user avatar
0 votes
1 answer
529 views

Laravel query order the inrandormorder query

I have 40 rows in my table, what i want is to get 20 row randomly, and after order these 5 list by id; these 2 in one query; for example in range of id 1 to 40; i get from the random order 15 10 14 9 ...
Michel Gisenaël's user avatar
0 votes
1 answer
121 views

Getting error in filter initialization in query builder

I am getting a string like this "{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{...
Prince Gajjar's user avatar
3 votes
1 answer
3k views

How do I use QueryBuilder with andWhere for json

please I am just new to querybuilder and precisely I don't know how to work with json object in a where clause. I would appreciate your swift assistance. "post_id": 1 "post": "...
Curtis Lanz's user avatar

1 2 3
4
5
52