query-builder

I've assigned Laravel Query Builder to a variable. It changes when being used

﹥>﹥吖頭↗ 提交于 2019-12-19 10:27:43
问题 it's a WHY-question, not How-to one:) I have assigned a Query Bulder to a variable $query: $query = table::where(['id'=>1, 'this_version'=> 1]); $versions['slug1'] = $query->select('tourist_id', 'tourist_version')->get()->toArray(); print_r($versions); outputs array with 2(!) sub-arrays: Array ( [slug1] => Array ( [0] => Array ( [tourist_id] => 1 [tourist_version] => 1 ) [1] => Array ( [tourist_id] => 2 [tourist_version] => 1 ) ) ) But if I add another line using $query between my $query

Dynamic linq Building Expression

跟風遠走 提交于 2019-12-19 04:08:46
问题 I need to create a dynamic linq expression for a dynamic search.The basic search is working but it fails to work with collection. I am able to get the book's title and author but fails to get the required page heading. I get the exception in line "left11 = Expression.Property(page1, "Heading");" . I think the expression that i built is unable to recognise the List. How could this be possible? Please see the below code and stacktrace exception. using System; using System.Collections.Generic;

How to match records that are associated with a specific set of other records?

試著忘記壹切 提交于 2019-12-18 09:46:44
问题 I am trying to add to two different search variations to my project. There is a model "User" and a model "Tag". A User has many Tags. Now I want to be able to search the Users with specific Tags. Either I want to show all Users that has any of the specified tags. I got this working this way: $query = $this->Users->find(); $query->matching('Tags', function ($q) { return $q->where(['Tags.name' => 'Tag1']) ->orWhere(['Tags.name' => 'Tag2']); }); But now I want to find all Users that have both

how to make laravel query builder like codeigniter active record

99封情书 提交于 2019-12-18 05:23:16
问题 I have a problem with Laravel 4 query builder, i want make a re-usable method public function getData($where=array()) { // $where = array('city' => 'jakarta', 'age' => '25'); return User::where($where)->get(); // this will produce an error, because i think laravel didn't support it } In CodeIgniter it easy to passing array to active record : public function getData($where=array()) { $rs = $this->db->where($where)->from('user')->get(); return $rs->result(); } // it will produce : // SELECT *

Laravel query builder General error 2031

折月煮酒 提交于 2019-12-18 04:55:13
问题 Below is my query using Laravel query builder: $begin = new DateTime('2016-07-01'); $end = new DateTime('2016-07-31'); $startDate = $begin->format('Y-m-d 00:00:00'); $endDate = $end->format('Y-m-d 23:59:59'); $deposit = $depositModel->select(DB::raw('user_deposit.user_id as user_id, sum(user_deposit.amount) as total_deposit, null as total_withdraw')) ->whereBetween('date_time', [$startDate, $endDate]) ->where('user_deposit.status', 1) ->groupBy('user_deposit.user_id'); $withdraw =

Symfony2 QueryBuilder join ON and WITH difference

一笑奈何 提交于 2019-12-18 03:49:34
问题 I'm new with Symfony2 and I built successfully my first join through QueryBuilder and Doctrine 2. Probably this is a stupid question but both on-line and in the Symfony2's methods I was unable to find anything for understanding the difference between the join clauses "WITH" and "ON". For example this is my join code: ->leftJoin('EcommerceProductBundle:ProductData', 'pdata', 'WITH', 'prod.id = IDENTITY(pdata.product)') It works good but if I put ON instead of WITH I get the following error:

How can I select specific Columns with createQueryBuilder in ORM Symfony2?

穿精又带淫゛_ 提交于 2019-12-18 01:57:33
问题 I'm using createQueryBuilder to construct queries in Symfony2. But, I don't want to take all columns in this entity. How can I select only the ID and Name? $query = $this->getEntityManager()->createQueryBuilder(); $query ->select('d') ->from('AcmeBundle:Demo', 'd') ->leftjoin('d.otherEntity', 'o'); $query->setMaxResults(10); $results = $query->getQuery()->getResult(); Thank you so much, 回答1: Try following, $fields = array('d.id', 'd.name', 'o.id'); //$fields = 'partial d.{id, name}, partial o

INNER JOIN Query + WHERE doesn't work

我们两清 提交于 2019-12-13 16:06:06
问题 I have two tables: contactperson and contactpersonlocale . Table contactperson : contactpersonID (Primary Key) tag (VARCHAR) Table contactpersonlocale : contactpersonlocaleID (Primary Key) contactpersonID (Foreign Key to contactperson table) function (VARCHAR) name (VARCHAR) locale (VARCHAR) In my Contactperson Entity I have: /** * @var integer * * @ORM\Column(name="contactpersonID", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $contactpersonid; /** * @ORM

laravel 'Allowed memory size of 134217728 bytes exhausted' on basic query

半世苍凉 提交于 2019-12-13 15:14:48
问题 I have no qlue why I can't get the following to work: DB::table('twitter_hashtags')->paginate(5); Every single time I get (the second number tends to differs) Allowed memory size of 134217728 bytes exhausted (tried to allocate 95735352 bytes) I tried using as in (18776710), but that did not make any difference DB::connection()->disableQueryLog(); Removing ->paginate(5) does not make any difference. When I try: DB::select('SELECT * FROM twitter_hashtags'); It works fine, but then I can't use

MySQL - Search into a custom Column

两盒软妹~` 提交于 2019-12-13 08:07:34
问题 I want to run a MySQL query like this- SELECT country_ID*2/id*3.159 as my_id FROM `state` WHERE my_id>2; When I run it, I am getting an error like this- 1054 - Unknown column 'my_id' in 'where clause' Is there any alternative solution to search in my new created virtual column my_id ? Actually I am trying to make a search in Laravel Query Builder like this- DB::table( 'project')->select( 'project.id as id', 'project.completion_date as completion_date', DB::raw('FORMAT(project.total_cost_to