Re: 3.0: Saving new entity with belongsToMany data

2015-01-22 Thread Joe T.
Yes, i agree i left that pretty open-ended. My apologies. And no offense 
intended toward you for not being able to follow up sooner. i've been busy 
too  just haven't been able to keep beating on this on my own.

In *App/Controller/Admin/ListingsController.php*, the Entity is created 
~line 124. Just inside the try{} i have 3 Log::debug lines, and according 
to the Debug plugin, those now have the data i expect (which is in a 
previous message on this thread). However, while the save now succeeds for 
the parent table (Listings), it still isn't saving anything to the 
associated child (ListingsAttrs).

i don't know if it's a problem with the way i'm setting up the fields  
thus that data is going into the POST:

// *App/Template/Element/Admin/Form/listing-attributes.ctp* produces this 
part of the POST data:
[listings_attrs] = Array (
[4] = Array (
[attr_id] = 4
)
[1] = Array (
[attr_id] = 1
[value] = Off-street
)
)

Or if it's something wrong with the Tables (
*App/Model/Table/ListingsTable.php*  
*App/Model/Table/ListingsAttrsTable.php*)
Or it's a problem with my Entity prep in the Controller.
Or something else i'm missing completely.

i didn't go into a lot of detail before as i hope it's just something 
simple that would jump out as wrong since you know how things *should* work.

As i noted before, being able to see this in action is behind a login i'd 
rather provide privately *if you can* take a little time to see it 
happening. If you don't have the time, i understand. Free advice  help has 
its limitations. You guys are already very generous helping me  the rest 
of the group. :)

Oh, hey, i just discovered the private reply menu item... i'll send the 
info that way.

Thanks again.
-joe


On Thursday, 22 January 2015 04:03:38 UTC-5, José Lorenzo wrote:

 No, I have not had the time to check the code. I was expecting something 
 more manageable for me to review and not a full application. Or at least 
 instructions for getting your code to run and where in your code the 
 problem is.

 On Thursday, January 22, 2015 at 5:39:21 AM UTC+1, Joe T. wrote:

 Did i get lost in the shuffle? i confess i've been busy with other things 
 myself, but have been checking here to see if there was any response with 
 some ideas what i'm doing wrong...

 Any help? Please? :)

 Always appreciated.
 -joe


 On Tuesday, 13 January 2015 08:04:37 UTC-5, Joe T. wrote:

 https://bitbucket.org/cautionbug/kodiak-investments

 The stuff i'm having trouble with is behind an admin login. If you need 
 access, i'd prefer to send that privately.

 Thanks for responding  being willing to take a look.

 -joe


 On Tuesday, 13 January 2015 03:38:36 UTC-5, José Lorenzo wrote:

 I think you should put your code somewhere so we can take a look, 
 otherwise trying to guess what the problem is will take a while.

 On Tuesday, January 13, 2015 at 4:02:56 AM UTC+1, Joe T. wrote:

 Wondering if someone can help me take a closer look at this... i'm 
 still not having any luck  can't really get much forward progress until 
 i 
 understand this.

 If you need more information to determine suggestions, let me know. 
 Any suggestions are appreciated.

 -joe


 On Tuesday, 30 December 2014 01:52:54 UTC-5, Joe T. wrote:

 i figured out part of my trouble, but the purpose of the original 
 post still remains.

 The parent record in Listings wasn't saving correctly because i 
 didn't have an `active` field in the form (*facepalm*). Corrected 
 that. Still having trouble with the date field, kinda frustrated there. 
 But 
 to the point...

 When i save my data, i'm now getting a record in Listings. Yay! But 
 the associated data in ListingsAttrs is still not there. Boo!

 Current structure of ListingsAttrs POST data:
 [listings_attrs] = Array (
 [4] = Array (
 [attr_id] = 4
 )
 [1] = Array (
 [attr_id] = 1
 [value] = Off-street
 )
 )

 Which now gives me this in the *$listing* Entity:
 listings_attrs: {
 4: {
 attr_id: 4
 },
 1: {
 attr_id: 1,
 value: Off-street
 }
 }

 This is progress! The associated data wasn't in previous debug data.

 So what am i still missing that it won't save that data? Remember, 
 `value` is optional to the data record, it's controlled by the UI. 
 So both of those records *should be* valid. Why then is neither of 
 them being saved?

 Any additional help here is appreciated.
 -joe t.


 On Monday, 22 December 2014 22:54:12 UTC-5, Joe T. wrote:

 Sorry this took several days to respond, i was sick all weekend, 
 didn't get anywhere near my computer.

 i changed the names of the inputs from *listingsattrs*  
 *listings_attrs* as you recommended (no clue how i missed that to 
 begin with). My POST data now looks exactly as it did before, except 
 for 
 the name of that particular item. However, the log output for the 
 $listing entity is still missing the associated ListingsAttrs data.

 The ListingsAttrs 

Re: Cake 3.0 - get source table and schema of each field in a recordset

2015-01-22 Thread José Lorenzo
The associations used in a find are represented in a Tree-like structure. I 
guess in your case it will be more than enough getting the first-level 
associations
of type belongsTo and hasOne, as those are the only types that can be 
represented in a html table (they are in the same level of nesting)

So to get associations of a table of type belongsTo and hasOne:

$firstLevelAssociations = 
collection($mainTable-associations()-type('HasOne'))
-append($mainTable-associations()-type('BelongsTo'));

$schemas = [];
foreach ($firstLevelAssociations as $association) {
   $schemas[$association-property()] = $association-schema();
}

At the end of the loop you will have an array of property names pointing to 
the table schema. So, finally:

foreach ($schemas as $property = $schema) {
   if ($singleResultFromQuery-has($property)) {
// Do stuff with the schema
   }
}


This is one way to do it. The other way is inspecting the query object to 
get the 'contain' tree. Let me know if you need to know more about it :)
On Thursday, January 22, 2015 at 11:01:35 AM UTC+1, Ernesto wrote:

 what about getting all the associations used in a record set?

 Il giorno giovedì 22 gennaio 2015 10:02:02 UTC+1, José Lorenzo ha scritto:

 foreach ($results as $result) {
 $source = $result-source();
 $sourceSchema = TableRegistry::get($source)-schema();
 }

 Usually all records in a result set are of the same table, so you on;y 
 need to do that for the first result.

 If you have associations, then you can get the property in the result:

 $associationSource = $result-association_property-source();


 On Thursday, January 22, 2015 at 9:07:31 AM UTC+1, Ernesto wrote:

 Hi all

 i'm migrating an HtmlTableHelper from a Cake 2.x project to  new 3.0 one

 The main function of this helper scans the array of data passed as 
 argument and uses ClassRegistry to obtain schemas for each Model.field.
 Later on these informations are used to format the TDs (text fields 
 justified to the left, number fields justified to the right and so on).

 in 3.0 data arrays are gone, replaced by resultsets.

 I tried to rewrite a similar approach but i'm struggling with Cake's new 
 ORM

 what's the best way to get source table and schema of each field in a 
 recordset?

 Thank you very much




-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3.0 - get source table and schema of each field in a recordset

2015-01-22 Thread José Lorenzo
Associations are already loaded, as you define them in the initialize() 
method of the table.

You can inspect the associations tree in a query by calling 
$query-eagerLoader()-normalized($query-repository());

On Thursday, January 22, 2015 at 2:47:35 PM UTC+1, Ernesto wrote:

 The inspect the contain tree way sounds better.

 i'll try to explain:

 With your method you will end up loading every belongsTo and hasOne 
 association, even if not used.
 The table i'm using right now has 3 belongsTo relationships but i need to 
 show only one

 On the second hand: first level association are not always enough.
 This worsen the problem quite a bit.
 if i use your method i must recursively loop throug tables and theyr 
 relationships, loading a ton of useless classes.

 What do you think?

 Il giorno giovedì 22 gennaio 2015 12:56:19 UTC+1, José Lorenzo ha scritto:

 The associations used in a find are represented in a Tree-like structure. 
 I guess in your case it will be more than enough getting the first-level 
 associations
 of type belongsTo and hasOne, as those are the only types that can be 
 represented in a html table (they are in the same level of nesting)

 So to get associations of a table of type belongsTo and hasOne:

 $firstLevelAssociations = 
 collection($mainTable-associations()-type('HasOne'))
 -append($mainTable-associations()-type('BelongsTo'));

 $schemas = [];
 foreach ($firstLevelAssociations as $association) {
$schemas[$association-property()] = $association-schema();
 }

 At the end of the loop you will have an array of property names pointing 
 to the table schema. So, finally:

 foreach ($schemas as $property = $schema) {
if ($singleResultFromQuery-has($property)) {
 // Do stuff with the schema
}
 }


 This is one way to do it. The other way is inspecting the query object to 
 get the 'contain' tree. Let me know if you need to know more about it :)
 On Thursday, January 22, 2015 at 11:01:35 AM UTC+1, Ernesto wrote:

 what about getting all the associations used in a record set?

 Il giorno giovedì 22 gennaio 2015 10:02:02 UTC+1, José Lorenzo ha 
 scritto:

 foreach ($results as $result) {
 $source = $result-source();
 $sourceSchema = TableRegistry::get($source)-schema();
 }

 Usually all records in a result set are of the same table, so you on;y 
 need to do that for the first result.

 If you have associations, then you can get the property in the result:

 $associationSource = $result-association_property-source();


 On Thursday, January 22, 2015 at 9:07:31 AM UTC+1, Ernesto wrote:

 Hi all

 i'm migrating an HtmlTableHelper from a Cake 2.x project to  new 3.0 
 one

 The main function of this helper scans the array of data passed as 
 argument and uses ClassRegistry to obtain schemas for each Model.field.
 Later on these informations are used to format the TDs (text fields 
 justified to the left, number fields justified to the right and so on).

 in 3.0 data arrays are gone, replaced by resultsets.

 I tried to rewrite a similar approach but i'm struggling with Cake's 
 new ORM

 what's the best way to get source table and schema of each field in a 
 recordset?

 Thank you very much




-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3.0 - get source table and schema of each field in a recordset

2015-01-22 Thread Ernesto
The inspect the contain tree way sounds better.

i'll try to explain:

With your method you will end up loading every belongsTo and hasOne 
association, even if not used.
The table i'm using right now has 3 belongsTo relationships but i need to 
show only one

On the second hand: first level association are not always enough.
This worsen the problem quite a bit.
if i use your method i must recursively loop throug tables and theyr 
relationships, loading a ton of useless classes.

What do you think?

Il giorno giovedì 22 gennaio 2015 12:56:19 UTC+1, José Lorenzo ha scritto:

 The associations used in a find are represented in a Tree-like structure. 
 I guess in your case it will be more than enough getting the first-level 
 associations
 of type belongsTo and hasOne, as those are the only types that can be 
 represented in a html table (they are in the same level of nesting)

 So to get associations of a table of type belongsTo and hasOne:

 $firstLevelAssociations = 
 collection($mainTable-associations()-type('HasOne'))
 -append($mainTable-associations()-type('BelongsTo'));

 $schemas = [];
 foreach ($firstLevelAssociations as $association) {
$schemas[$association-property()] = $association-schema();
 }

 At the end of the loop you will have an array of property names pointing 
 to the table schema. So, finally:

 foreach ($schemas as $property = $schema) {
if ($singleResultFromQuery-has($property)) {
 // Do stuff with the schema
}
 }


 This is one way to do it. The other way is inspecting the query object to 
 get the 'contain' tree. Let me know if you need to know more about it :)
 On Thursday, January 22, 2015 at 11:01:35 AM UTC+1, Ernesto wrote:

 what about getting all the associations used in a record set?

 Il giorno giovedì 22 gennaio 2015 10:02:02 UTC+1, José Lorenzo ha scritto:

 foreach ($results as $result) {
 $source = $result-source();
 $sourceSchema = TableRegistry::get($source)-schema();
 }

 Usually all records in a result set are of the same table, so you on;y 
 need to do that for the first result.

 If you have associations, then you can get the property in the result:

 $associationSource = $result-association_property-source();


 On Thursday, January 22, 2015 at 9:07:31 AM UTC+1, Ernesto wrote:

 Hi all

 i'm migrating an HtmlTableHelper from a Cake 2.x project to  new 3.0 one

 The main function of this helper scans the array of data passed as 
 argument and uses ClassRegistry to obtain schemas for each Model.field.
 Later on these informations are used to format the TDs (text fields 
 justified to the left, number fields justified to the right and so on).

 in 3.0 data arrays are gone, replaced by resultsets.

 I tried to rewrite a similar approach but i'm struggling with Cake's 
 new ORM

 what's the best way to get source table and schema of each field in a 
 recordset?

 Thank you very much




-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Cake 3.0 - get source table and schema of each field in a recordset

2015-01-22 Thread Ernesto
Hi all

i'm migrating an HtmlTableHelper from a Cake 2.x project to  new 3.0 one

The main function of this helper scans the array of data passed as argument 
and uses ClassRegistry to obtain schemas for each Model.field.
Later on these informations are used to format the TDs (text fields 
justified to the left, number fields justified to the right and so on).

in 3.0 data arrays are gone, replaced by resultsets.

I tried to rewrite a similar approach but i'm struggling with Cake's new ORM

what's the best way to get source table and schema of each field in a 
recordset?

Thank you very much


-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3.0 - get source table and schema of each field in a recordset

2015-01-22 Thread Ernesto
what about getting all the associations used in a record set?

Il giorno giovedì 22 gennaio 2015 10:02:02 UTC+1, José Lorenzo ha scritto:

 foreach ($results as $result) {
 $source = $result-source();
 $sourceSchema = TableRegistry::get($source)-schema();
 }

 Usually all records in a result set are of the same table, so you on;y 
 need to do that for the first result.

 If you have associations, then you can get the property in the result:

 $associationSource = $result-association_property-source();


 On Thursday, January 22, 2015 at 9:07:31 AM UTC+1, Ernesto wrote:

 Hi all

 i'm migrating an HtmlTableHelper from a Cake 2.x project to  new 3.0 one

 The main function of this helper scans the array of data passed as 
 argument and uses ClassRegistry to obtain schemas for each Model.field.
 Later on these informations are used to format the TDs (text fields 
 justified to the left, number fields justified to the right and so on).

 in 3.0 data arrays are gone, replaced by resultsets.

 I tried to rewrite a similar approach but i'm struggling with Cake's new 
 ORM

 what's the best way to get source table and schema of each field in a 
 recordset?

 Thank you very much




-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with Session and PHP Unit Test

2015-01-22 Thread monica
Thank you Mark ;) but it haven't solved the problem.

I've tried couple of times to use it ($this-session). 
My first attempt:

public function testResetFilters() {
  $this-session([
   'WhatIsInside' = 'littlebunny',
   'CurrentFilter' = 'this is the filter'
  ]);
  $expected_filter = 'this is the filter';
  $this-assertSession($expected_filter, 
'CurrentFilter');
}

but still test failed.

I tried also to read from session:

public function testResetFilters() {
  $this-session([
   'WhatIsInside' = 'littlebunny',
   'CurrentFilter' = 'this is the filter'
  ]);
  $oldUserSession = $this-session(['CurrentFilter']);
  
  $this-assertSession($oldUserSession, 
'CurrentFilter');
}

But this one also failed. 

Am I using properly assertSession()?
How to read from the session when you are writing to it using 
$this-session()?




On Wednesday, 21 January 2015 15:23:12 UTC, euromark wrote:

 in 3.x the --stderr of course is not necessary anymore

 For 3.x please use the IntegrationTest as it is designed, so add

 $this-session($data), instead of actually writing to the session.

 Mark



 Am Mittwoch, 21. Januar 2015 12:49:17 UTC+1 schrieb monica:

 Thanks mark for tip ;)

 I've checked with that option and nothing really changed. I forgot to 
 mention it's cakephp 3.0.
 This is the command I'm running:

 php phpunit.phar --stderr -v tests/TestCase/Controller/
 UnitTestsControllerTest.php





 On Tuesday, 20 January 2015 18:58:47 UTC, euromark wrote:

 Dont forget --stderr when testing 2.x tests in CLI

 mark


 Am Dienstag, 20. Januar 2015 13:29:47 UTC+1 schrieb monica:

 Hi!

 I baked new UnitTestsController for testing purposes and put inside the 
 function:


 public function reset_filters() {
  // suppose to delete CurrentFilter var from session
  this-request-session()-delete('CurrentFilter');
 }


 I wanted to test session so I baked also UnitTestsControllerTest.php 

 public function testResetFilters() {
  $session = new Session;
  
  $session-write([
 'WhatIsInside' = 'littlebunny',
 'CurrentFilter' = 'this is the filter'
 ]);
  
  // saving one of session vars
  $oldUserSession = $session-read('WhatIsInside');
  
  // calling function which suppose to delete the other session 
 var (CurrentFilter) and leave WhatIsInside session var untouched
  $this-get('/UnitTests/reset_filters');
  
  // getting that other var from session
  $newUserSession = $session-read('WhatIsInside');

  // checking if function hasn't deleted the other session vars
  $this-assertSame($oldUserSession, $newUserSession);
 }


 But the test *failed*. 

 I printed content of both sessions data before and after function.
 Before function is giving me correct output but after calling the 
 function it's giving me null.

 Console output:


 There was 1 failure:

 1) 
 App\Test\TestCase\Controller\UnitTestsControllerTest::testResetFilters
 Failed asserting that null is identical to 'littlebunny'.



 I don't what I did wrong and any help will be appreciated. 


-- 


*** CONFIDENTIALITY NOTICE AND LEGAL LIABILITY WAIVER ***

The content of this email and any attachments are CONFIDENTIAL and may 
contain privileged information. If you are not the addressee it may be 
UNLAWFUL for you to read, copy, distribute or disclose the information 
contained herein. This email and any attachments may not reflect the 
opinions of the originating company or any party it is representing. 
Telephone calls may be recorded for training and quality monitoring 
purposes.

The Car Finance Company (2007) Ltd Registered Address is 47-51 Kingston 
Crescent, Portsmouth, PO2 8AA and is authorised and regulated by the 
Financial Conduct Authority, CCL number 600168. 

The Car Finance Company (Trade Sales) Ltd is a wholly owned subsidiary of 
The Car Finance Company (2007) Ltd. Registered Address is 47-51 Kingston 
Crescent, Portsmouth, PO2 8AA and is authorised and regulated by the 
Financial Conduct Authority, CCL number 663690.

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Iter of cakephp tests

2015-01-22 Thread Alessandro Minoccheri
Hi all
I'm writing hereu to understand well cakephp tests.

I mean about this issue: 
https://github.com/cakephp/cakephp/issues/5693#issuecomment-70532382

So my question is:
How to make good tests?
Because in cakephp documentation isn't exaplained well I think or I haven't 
understand well the correct iter.

What I have always done:
- Created default database
- Created test database
- Populated the default database
- Exported all database and imported into the tests database with all 
records
- Started to create test
- Created fixtures with declarations of fields and records
- Created tests model that load fixtures.

I thinked that when I'm starting to test when the framework load fixtures 
delete the table of the fixtures and redraw it with field and records.
Is wrong right?
Database table are dropped after tests I have read

Ok, so what is the good way to insert my records into database tests?
Repopulate the database tests from phpmyadmin for example? 

But in this way what is the purpose of the $records array in fixtures?

I would like to know the best practice to create a great workflow for tests

Thanks

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


cakephp tests best practice

2015-01-22 Thread Alessandro Minoccheri
Hi all,
I'm writing here to understand the right iter for cakephp tests.

I mean about this issue: 
https://github.com/cakephp/cakephp/issues/5693#issuecomment-70532382

So my question is:
How to make good tests?
Because in cakephp documentation isn't explained well I think or I haven0t 
understand the best practice to create tests.

What I have done in my cakephp site:
- Created default database
- Created test database
- Populated the default database
- Exported all database and imported into the tests database with all 
records
- Started to create test
- Created fixtures with declarations of fields and records
- Created tests model that load fixtures.

I thinked that when I'm starting to test when the framework load fixtures 
delete the table of the fixtures and redraw it with field and records.
Is wrong right?
Database table are dropped after tests I have read

Ok, so what is the good way to insert my records into database tests?
Repopulate the database tests from phpmyadmin for example? But in this way 
what is the purpose of the $records array in fixtures?

What is the right iter to create a great tests workflow?

Thanks


-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3.0 - get source table and schema of each field in a recordset

2015-01-22 Thread José Lorenzo
foreach ($results as $result) {
$source = $result-source();
$sourceSchema = TableRegistry::get($source)-schema();
}

Usually all records in a result set are of the same table, so you on;y need 
to do that for the first result.

If you have associations, then you can get the property in the result:

$associationSource = $result-association_property-source();


On Thursday, January 22, 2015 at 9:07:31 AM UTC+1, Ernesto wrote:

 Hi all

 i'm migrating an HtmlTableHelper from a Cake 2.x project to  new 3.0 one

 The main function of this helper scans the array of data passed as 
 argument and uses ClassRegistry to obtain schemas for each Model.field.
 Later on these informations are used to format the TDs (text fields 
 justified to the left, number fields justified to the right and so on).

 in 3.0 data arrays are gone, replaced by resultsets.

 I tried to rewrite a similar approach but i'm struggling with Cake's new 
 ORM

 what's the best way to get source table and schema of each field in a 
 recordset?

 Thank you very much




-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0: Saving new entity with belongsToMany data

2015-01-22 Thread José Lorenzo
No, I have not had the time to check the code. I was expecting something 
more manageable for me to review and not a full application. Or at least 
instructions for getting your code to run and where in your code the 
problem is.

On Thursday, January 22, 2015 at 5:39:21 AM UTC+1, Joe T. wrote:

 Did i get lost in the shuffle? i confess i've been busy with other things 
 myself, but have been checking here to see if there was any response with 
 some ideas what i'm doing wrong...

 Any help? Please? :)

 Always appreciated.
 -joe


 On Tuesday, 13 January 2015 08:04:37 UTC-5, Joe T. wrote:

 https://bitbucket.org/cautionbug/kodiak-investments

 The stuff i'm having trouble with is behind an admin login. If you need 
 access, i'd prefer to send that privately.

 Thanks for responding  being willing to take a look.

 -joe


 On Tuesday, 13 January 2015 03:38:36 UTC-5, José Lorenzo wrote:

 I think you should put your code somewhere so we can take a look, 
 otherwise trying to guess what the problem is will take a while.

 On Tuesday, January 13, 2015 at 4:02:56 AM UTC+1, Joe T. wrote:

 Wondering if someone can help me take a closer look at this... i'm 
 still not having any luck  can't really get much forward progress until i 
 understand this.

 If you need more information to determine suggestions, let me know. Any 
 suggestions are appreciated.

 -joe


 On Tuesday, 30 December 2014 01:52:54 UTC-5, Joe T. wrote:

 i figured out part of my trouble, but the purpose of the original post 
 still remains.

 The parent record in Listings wasn't saving correctly because i didn't 
 have an `active` field in the form (*facepalm*). Corrected that. 
 Still having trouble with the date field, kinda frustrated there. But to 
 the point...

 When i save my data, i'm now getting a record in Listings. Yay! But 
 the associated data in ListingsAttrs is still not there. Boo!

 Current structure of ListingsAttrs POST data:
 [listings_attrs] = Array (
 [4] = Array (
 [attr_id] = 4
 )
 [1] = Array (
 [attr_id] = 1
 [value] = Off-street
 )
 )

 Which now gives me this in the *$listing* Entity:
 listings_attrs: {
 4: {
 attr_id: 4
 },
 1: {
 attr_id: 1,
 value: Off-street
 }
 }

 This is progress! The associated data wasn't in previous debug data.

 So what am i still missing that it won't save that data? Remember, 
 `value` is optional to the data record, it's controlled by the UI. So 
 both of those records *should be* valid. Why then is neither of them 
 being saved?

 Any additional help here is appreciated.
 -joe t.


 On Monday, 22 December 2014 22:54:12 UTC-5, Joe T. wrote:

 Sorry this took several days to respond, i was sick all weekend, 
 didn't get anywhere near my computer.

 i changed the names of the inputs from *listingsattrs*  
 *listings_attrs* as you recommended (no clue how i missed that to 
 begin with). My POST data now looks exactly as it did before, except for 
 the name of that particular item. However, the log output for the 
 $listing entity is still missing the associated ListingsAttrs data.

 The ListingsAttrs Entity didn't have a $_accessible array, so i 
 added a default:
 $_accessible = [
   '*' = true
 ];

 The controller code looks like:
 $listing = $this-Listings-newEntity($this-request-data);

 /* i've also tried:
 $listing = $this-Listings-newEntity($this-request-data, 
 ['associated' = ['ListingsAttrs']]);
 $listing = $this-Listings-newEntity($this-request-data, 
 ['associated' = ['ItemAttrs']]);
 $listing = $this-Listings-newEntity($this-request-data, 
 ['associated' = ['ListingsAttrs.ItemAttrs']]);
 $listing = $this-Listings-newEntity($this-request-data, 
 ['associated' = ['ItemAttrs.ListingsAttrs']]);
 */

 if ($this-Listings-save($listing)) {
   // etc.
 }
 else {
   throw new Exception...
 }

 What else can i try? i appreciate the help.
 -joe

 On Friday, 19 December 2014 11:29:12 UTC-5, José Lorenzo wrote:

 You should post a property called listings_attrs, check your entity 
 $_accessible array to make sure the property is also writable with 
 request 
 data.

 On Friday, December 19, 2014 6:29:43 AM UTC+1, Joe T. wrote:

 i've seen a couple similar threads about this, but not my exact 
 problem.

 i'm trying to follow the guide here: 
 http://book.cakephp.org/3.0/en/orm/saving-data.html#converting-request-data-into-entities
  
 and coming up short. *i'm not getting any errors* (except a date 
 field that constantly fails if it has a value, separate issue)...so i 
 have 
 no idea what's happening to the data i submit, or why it isn't saved 
 to the 
 DB.

 My raw response data logged to Cake Debug is:

 Array (
   [title] = '123 Main St'
   [street] = '123 Main St'
   [lot_no] = 1
   [lat] =
   [lng] =
   [city] = 'Hometown'
   [county] = 
   [state] = 'MI'
   [zip] = '49000'
   [area] = 900 
   [bedrooms] = 2 
   [bathrooms] = 1 
   [price] = 525 
   [ready_date] =
   [listingsattrs] = 

Re: Cake 3.0 - get source table and schema of each field in a recordset

2015-01-22 Thread Ernesto
Ok i'll try.

i'll let you know

Thank you very much

Il giorno giovedì 22 gennaio 2015 15:30:51 UTC+1, José Lorenzo ha scritto:

 Associations are already loaded, as you define them in the initialize() 
 method of the table.

 You can inspect the associations tree in a query by calling 
 $query-eagerLoader()-normalized($query-repository());

 On Thursday, January 22, 2015 at 2:47:35 PM UTC+1, Ernesto wrote:

 The inspect the contain tree way sounds better.

 i'll try to explain:

 With your method you will end up loading every belongsTo and hasOne 
 association, even if not used.
 The table i'm using right now has 3 belongsTo relationships but i need to 
 show only one

 On the second hand: first level association are not always enough.
 This worsen the problem quite a bit.
 if i use your method i must recursively loop throug tables and theyr 
 relationships, loading a ton of useless classes.

 What do you think?

 Il giorno giovedì 22 gennaio 2015 12:56:19 UTC+1, José Lorenzo ha scritto:

 The associations used in a find are represented in a Tree-like 
 structure. I guess in your case it will be more than enough getting the 
 first-level associations
 of type belongsTo and hasOne, as those are the only types that can be 
 represented in a html table (they are in the same level of nesting)

 So to get associations of a table of type belongsTo and hasOne:

 $firstLevelAssociations = 
 collection($mainTable-associations()-type('HasOne'))
 -append($mainTable-associations()-type('BelongsTo'));

 $schemas = [];
 foreach ($firstLevelAssociations as $association) {
$schemas[$association-property()] = $association-schema();
 }

 At the end of the loop you will have an array of property names pointing 
 to the table schema. So, finally:

 foreach ($schemas as $property = $schema) {
if ($singleResultFromQuery-has($property)) {
 // Do stuff with the schema
}
 }


 This is one way to do it. The other way is inspecting the query object 
 to get the 'contain' tree. Let me know if you need to know more about it :)
 On Thursday, January 22, 2015 at 11:01:35 AM UTC+1, Ernesto wrote:

 what about getting all the associations used in a record set?

 Il giorno giovedì 22 gennaio 2015 10:02:02 UTC+1, José Lorenzo ha 
 scritto:

 foreach ($results as $result) {
 $source = $result-source();
 $sourceSchema = TableRegistry::get($source)-schema();
 }

 Usually all records in a result set are of the same table, so you on;y 
 need to do that for the first result.

 If you have associations, then you can get the property in the result:

 $associationSource = $result-association_property-source();


 On Thursday, January 22, 2015 at 9:07:31 AM UTC+1, Ernesto wrote:

 Hi all

 i'm migrating an HtmlTableHelper from a Cake 2.x project to  new 3.0 
 one

 The main function of this helper scans the array of data passed as 
 argument and uses ClassRegistry to obtain schemas for each Model.field.
 Later on these informations are used to format the TDs (text fields 
 justified to the left, number fields justified to the right and so on).

 in 3.0 data arrays are gone, replaced by resultsets.

 I tried to rewrite a similar approach but i'm struggling with Cake's 
 new ORM

 what's the best way to get source table and schema of each field in a 
 recordset?

 Thank you very much




-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: CakePHP 3.0, Any chat application for cakephp?

2015-01-22 Thread Jungsuk Lee
Oh I didn't know that there is a web socket available in cakephp. Thank 
you!!

Hi I'm working on cakephp to build a website and i'd like to add chatting 
 feature in it.
 and I'm considering Javascript based chat application.

 Using AJAX was too slow to use. any other way?
 Please help.

 Thank you in advance!


-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.