Well that's good news, much is made of the new ORM, but it seems as though
bread and butter (not cake :) queries can be constructed in the same way
that they could before (CakePHP 2) using contain?
Having watched your recent video release - 'Faster application development
with CakePHP 3.0' I understand that you love and are passionate about SQL.
Not everybody is, and I'm one of them. I want as much of the pain taken out
of it as possible of constructing the SQL and find that the format below
serves me well for about 98% of what I'm after.
Thanks for the reply
Dave
On Tuesday, 31 March 2015 08:33:16 UTC+1, José Lorenzo wrote:
> Hopefully from our previous messages you can guess it yourself:
>
> $options = array(
> 'conditions' => array(
> 'Rentals.id' => $id,
>
> ),
> 'contain' => array(
> 'Trailers' => array(
>
> 'fields' => array('id', 'number', 'make',
> 'year', 'license', 'vin', 'skirt')
> ),
> 'Lessees' => array(
> 'fields' => array('id', 'account', 'name',
> 'address_1', 'address_2', 'city', 'state', 'zip_1', 'zip_2')
> )
> )
> );
>
>
> $rental = $this->Rentals->find('all', $options)->first();
>
> You can also use the where(), select() and contain() methods if you prefer
> not using an array.
>
> On Monday, March 30, 2015 at 10:29:40 PM UTC+2, Dave Edwards wrote:
>>
>> BUMP!
>>
>> On Tuesday, 24 March 2015 20:33:49 UTC, Dave Edwards wrote:
>>>
>>> Thanks for the reply,
>>>
>>> That being the case, I am pleasantly surprised that despite the
>>> documentation making a big play on how different the new ORM is, I can (if
>>> I choose) create my queries in much the same way.
>>>
>>> The example I posted was a effectively a find 'all' (paginated using a
>>> limit clause). What about a find first, is this still as straightforward?
>>> Here is an example from the same controller, how would that translate
>>> please?
>>>
>>>
>>> $options = array(
>>> 'conditions' => array(
>>> 'Rental.id' => $id,
>>> ),
>>> 'contain' => array(
>>> 'Trailer' => array(
>>> 'fields' => array('id', 'number', 'make',
>>> 'year', 'license', 'vin', 'skirt')
>>> ),
>>> 'Lessee' => array(
>>> 'fields' => array('id', 'account', 'name',
>>> 'address_1', 'address_2', 'city', 'state', 'zip_1', 'zip_2')
>>> )
>>> )
>>> );
>>>
>>>
>>> $this->request->data = $this->Rental->find('first', $options
>>> );
>>>
>>> Dave
>>>
>>> On Tuesday, 24 March 2015 13:04:21 UTC, Dave Edwards wrote:
>>>>
>>>> Here is a sample of some code I use in a Trailer rental application.
>>>> This is a method from the Rental Controller.
>>>>
>>>> Rental hasMany Trailers and hasMany Lessees
>>>>
>>>> public function archived($id = null) {
>>>>
>>>>
>>>> $options = array(
>>>> 'limit' => 10,
>>>> 'order' => 'Trailer.number ASC',
>>>> 'fields' => array('id', 'trailer_id', 'lessee_id', 'date_out'
>>>> , 'rented', 'agreement_number'),
>>>> 'conditions' => array(
>>>> 'Rental.deleted' => '1',
>>>> ),
>>>> 'contain' => array(
>>>> 'Trailer' => array(
>>>> 'fields' => array('id', 'number', 'make', 'license'),
>>>> ),
>>>> 'Lessee' => array(
>>>> 'fields' => array('id', 'account', 'name'),
>>>> )
>>>> )
>>>> );
>>>>
>>>>
>>>> $this->paginate = $options;
>>>> $this->set('rentals', $this->paginate());
>>>> }
>>>>
>>>>
>>>> Turning off recursive, and using Containable provides a very flexible
>>>> and readable method of building a query. Adding conditions, fields,
>>>> associated models etc is a snip. Whoever produced this method of working
>>>> should be fully credited.
>>>>
>>>> My question is, how would something like this be created in CakePHP 3?
>>>> There seem to be many many more pages to read and understand regarding the
>>>> new ORM, and I'm really unsure how simple it will be to convert. Will I be
>>>> able to achieve it in the a similar manner, and will it be as readable,
>>>> and
>>>> easy to edit?
>>>>
>>>> Are there any examples in the new Manual (I can't find any), where the
>>>> new ORM is used to bring all the new methods of working together in much
>>>> the same way as the method above?
>>>>
>>>> Thanks
>>>>
>>>> Dave
>>>>
>>>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.