Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the table schema/columns from an entity object in cakephp 3?

Let's say I have a bonified \Cake\ORM\Entity object -- $kablammo I can confirm and make sure it has an associated repository by doing the following:

use Cake\ORM\Entity;

// ..snip

if ($kablammo instanceOf Entity && !empty($kablammo->source())) {
    $repository = $kablammo->source();
    // ... what do I do here to get the table schema info/columns?
}

I'd like to be able to view the table columns for this Entity's associated table basically. What's the best way to do this? Am I going about it wrong already?

like image 558
Kevin Avatar asked Apr 23 '15 02:04

Kevin


1 Answers

I think I figured it out.

use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;

// ..snip

if ($kablammo instanceOf Entity && !empty($kablammo->source())) {
    $repository = $kablammo->source();
    $table = TableRegistry::get($repository);
    debug($table->schema());
}

At least I'm on the right track now.

like image 188
Kevin Avatar answered Oct 21 '22 05:10

Kevin