query-builder

Doctrine Query Builder nested orX and andX conditions with join

本秂侑毒 提交于 2019-12-23 14:02:56
问题 I have two entities User and CalendarEvent . My users are attached to a factory, and calendarEvent can be used to know if a user is "loaned" to a different factory of the one he belongs to... My two entities are like this : User : class User extends BaseUser { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @var string * @ORM\Column(name="firstname", type="string", length=255, nullable=true) */ private $firstname; /** * @var string *

NOT IN query with Doctrine QueryBuilder in a Many to Many relation

旧巷老猫 提交于 2019-12-23 12:37:52
问题 In my Symfony2 project, I have two entities "contact" and "settings", with a many to many relationship : /** * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Settings", cascade={"persist"}) * @ORM\JoinColumn(nullable=true) */ private $settings; Entity settings have a property "parametre", which is a simple string. Now I want to get all the contacts that DON'T have any settings which "parametre" is "THEMES". I can do that in SQL with a query like : SELECT DISTINCT(c.id) FROM contact c WHERE c

SELECT sub-query with WHERE condition in Yii2 find() / QueryBuilder

谁说我不能喝 提交于 2019-12-23 11:52:39
问题 I was able to find simple examples of sub-query building, but am unable to figure out nor find the solution when I need to include a WHERE condition. I am trying to simulate the following statement... SELECT ParentTable.*, (SELECT MAX(ChildTable.NumberField) FROM ChildTable WHERE ChildTable.FK_Id = ParentTable.Id) FROM ParentTable Guess I'd need something like... $query = ParentClass::find() ->addSelect( ChildClass::find() ->where('childTable.fk_id=parentTable.id') ->max('childTable.field1')

Treating null field as zero for an update query

淺唱寂寞╮ 提交于 2019-12-23 04:47:07
问题 I'm using the SQL Express 2010 query builder. I need to be able to increment a field. In my behind code, I make a call such as tableAdapter.IncrementLikeCount(id); If I just use an increment, the like field can be null, so I want to either a. treat the null as zero in that field OR b. set to 1, if null, and increment otherwise. The most current thing I tried is option b with the following code in the query builder: UPDATE [dbo].[myTable] SET [LikeCount] = IIF(ISNULL([LikeCount]), 1, LikeCount

How to get the defined field in sonataadmin query builder?

喜夏-厌秋 提交于 2019-12-23 04:27:03
问题 There is the following code $form->with('Item')->add('parent', null, array( 'label' => 'Category', 'required' => true, 'query_builder' => function($er) use ($id) { $qb = $er->createQueryBuilder('p'); if ($id){ $qb->where('p.id <> :id') ->setParameter('id', $id); } $qb->orderBy('p.root, p.lft', 'ASC'); return $qb; } ......... Result is the entity-objects collection which is given to the string (__toString method). It return name-field. But I need get the another field - url. How to get url

NOT IN statement for Visual Studio's Query Builder for TableAdapter

一世执手 提交于 2019-12-23 03:23:22
问题 I want to realize a query with the Visual Studio 2008 build in Query Builder for a TableAdapter similar like following (MSSQL 2008): select * from [MyDB].[dbo].[MyView] where UNIQUE_ID NOT IN ('MyUniqueID1','MyUniqueID2') How do I have to set the Filter in my query in order to call it with the myTableAdapter.GetDataExceptUniqueIds(...) function? I tried to set the filter to NOT IN (@ids) and called it with string[] uniqueIds = ...; myTableAdapter.GetDataExceptUniqueIds(String.Join("','",

Left join to get a single row in Laravel

泪湿孤枕 提交于 2019-12-22 04:39:36
问题 I have been unsuccessfully trying to leftjoin and get the required data Here is my code: $album = Albums::->where('users_id',$user_id) ->leftJoin('photos',function($query){ $query->on('photos.albums_id','=','albums.id'); $query->where('photos.status','=',1); // $query->limit(1); // $query->min('photos.created_at'); }) ->where('albums.status',1)->get(); The comments are some of my several trying... I want to get only a single record from the photos table matching the foreign key album_id which

Could you recommend a JQuery plugin to compose a set of conditions mappable to a SQL query? [closed]

牧云@^-^@ 提交于 2019-12-21 02:28:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I've found http://redquerybuilder.appspot.com/ but that generates SQL client side which I want to avoid. On hat page there is a link to JQuery Query Builder plugin but that link goes to jquery home page. Seems that this plugin does nto exist anymore (also see Simple SQL Query Builder in JQuery for same link). I

DB query builder toArray() laravel 4

无人久伴 提交于 2019-12-20 10:22:38
问题 I'm trying to convert a query to an array with the method toArray() but it doesn't work for the query builder. Any ideas for convert it? Example DB::table('user')->where('name',=,'Jhon')->get()->toArray(); 回答1: toArray is a model method of Eloquent, so you need to a Eloquent model, try this: User::where('name', '=', 'Jhon')->get()->toArray(); http://laravel.com/docs/eloquent#collections 回答2: If you prefer to use Query Builder instead of Eloquent here is the solutions $result = DB::table('user

Passing parameter to SQL select statement IN clause acts weird.

不问归期 提交于 2019-12-20 03:32:20
问题 I've got the following query that returns 2 records (in DataSet's query builder) SELECT EmpID, Name, id FROM Users WHERE (CAST(id AS Varchar(20)) IN ('5688','5689')) Now if I do the same query passing the parameter instead from code behind: String param = "'5688','5689'"; it returns null. WHERE (CAST(id AS Varchar(20)) IN (@param)) I tried taking off the very first and last ', but that did not make a diffrence. !!!id is a unique PK!!! Anyone's got a clue? 回答1: The solution I found is quite