私のコントローラの1つである内腔アプリケーションでlaravel doctrineを使用していますが、私は与えられたエンティティからすべてのレコードを返すインデックス関数を持っています。Laravel doctrineはfindAll()クエリから単一の属性を返すだけです
機能は、これは、エンティティにおける1つの属性のみである。この
[
{
"nodeType": 'showOff'
},
{
"nodeType": 'showOff'
},
{
"nodeType": 'showOff'
},
{
"nodeType": 'showOff'
}
]
のようなデータを返します。この
public function index(ServerRequestInterface $request)
{
return $this->showResponse(app()->make('em')->getRepository('App\Entities\showOff')->findAll());
}
のように見えます。
私は上の教義デバッガを有効にした場合は、それが必要として、それはすべてのデータを返しますmysqlのコマンドラインから実行したときに
SELECT t0.type AS type_1, t0.size AS size_2, t0.last_modified AS last_modified_3, t0.hair_cutter AS hair_cutter_4, t0.file_path AS file_path_5, t0.content_url AS content_url_6, t0.embed_url AS embed_url_7, t0.height AS height_8, t0.width AS width_9, t0.player_type AS player_type_10, t0.about AS about_11, t0.award AS award_12, t0.comment AS comment_13, t0.comment_count AS comment_count_14, t0.text AS text_15, t0.thumbnail AS thumbnail_16, t0.version AS version_17, t0.name AS name_18, t0.id AS id_19, t0.nid AS nid_20, t0.node_type AS node_type_21, t0.owner_id AS owner_id_22, t23.enabled AS enabled_24, t23.username AS username_25, t23.email AS email_26, t23.password AS password_27, t23.remember_token AS remember_token_28, t23.name AS name_29, t23.id AS id_30, t23.nid AS nid_31, t23.node_type AS node_type_32, t0.aggregate_rating_id AS aggregate_rating_id_33, t34.rating_count AS rating_count_35, t34.rating_score AS rating_score_36, t34.name AS name_37, t34.id AS id_38, t34.nid AS nid_39, t34.node_type AS node_type_40, t0.author_id AS author_id_41, t42.enabled AS enabled_43, t42.username AS username_44, t42.email AS email_45, t42.password AS password_46, t42.remember_token AS remember_token_47, t42.name AS name_48, t42.id AS id_49, t42.nid AS nid_50, t42.node_type AS node_type_51, t0.translator_id AS translator_id_52, t53.enabled AS enabled_54, t53.username AS username_55, t53.email AS email_56, t53.password AS password_57, t53.remember_token AS remember_token_58, t53.name AS name_59, t53.id AS id_60, t53.nid AS nid_61, t53.node_type AS node_type_62 FROM show_off t0 LEFT JOIN users t23 ON t0.owner_id = t23.id LEFT JOIN aggregate_rating t34 ON t0.aggregate_rating_id = t34.id LEFT JOIN users t42 ON t0.author_id = t42.id LEFT JOIN users t53 ON t0.translator_id = t53.id ;
のように実行されるSQLクエリを参照してくださいです。
いくつかの行に沿って、私のすべての属性が取り除かれています。
私のエンティティがどのように見えるので
<?php
namespace App\Entities;
use Doctrine\ORM\Mapping as ORM;
use App\Jobs\IndexNewEntitiesJob;
use App\Jobs\UpdateIndexEntitiesJob;
use Doctrine\Common\Collections\ArrayCollection;
use ApiArchitect\Compass\Entities\User;
/**
* Class ShowOff
*
* @package Jkirkby91\DoctrineSchemas
* @author James Kirkby <[email protected]>
*
* @ORM\Entity
* @ORM\HasLifeCycleCallbacks
* @ORM\Table(name="show_off")
* @ORM\Entity(repositoryClass="App\Repositories\ShowOffRepository")
*/
class ShowOff extends \App\Entities\MediaObject
{
/**
* @ORM\Column(type="string", length=45, nullable=false, unique=false)
*/
protected $type;
/**
* @ORM\Column(type="integer", length=45, nullable=false)
*/
protected $size;
/**
* @ORM\Column(type="datetime", length=45, nullable=false, unique=false)
*/
protected $lastModified;
/**
* @ORM\OneToOne(targetEntity="\ApiArchitect\Compass\Entities\User", fetch="EAGER", cascade={"persist"})
*/
protected $owner;
/**
* @ORM\OneToOne(targetEntity="\App\Entities\HairCutter", fetch="EAGER", cascade={"persist"})
* @ORM\Column(nullable=true, unique=false)
*/
protected $hairCutter;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $filePath;
/**
* HairCutter constructor.
* @param $fileName
* @param $filePath
* @param $owner
* @param $hairCutter
*/
public function __construct($fileName, $filePath, User $owner, $type, $lastModified, $size)
{
$this->name = $fileName;
$this->filePath = $filePath;
$this->owner = $owner;
$this->type = $type;
$this->lastModified = $lastModified;
$this->size = $size;
$this->nodeType = 'showOff';
}
/**
* Gets the value of filePath.
*
* @return mixed
*/
public function getFilePath()
{
return $this->filePath;
}
/**
* Sets the value of filePath.
*
* @param mixed $filePath the file path
*
* @return self
*/
protected function setFilePath($filePath)
{
$this->filePath = $filePath;
return $this;
}
/**
* Gets the value of owner.
*
* @return mixed
*/
public function getOwner()
{
return $this->owner;
}
/**
* Sets the value of owner.
*
* @param mixed $owner the owner
*
* @return self
*/
protected function setOwner(User $owner)
{
$this->owner = $owner;
return $this;
}
/**
* Gets the value of hairCutter.
*
* @return mixed
*/
public function getHairCutter()
{
return $this->hairCutter;
}
/**
* Sets the value of hairCutter.
*
* @param mixed $hairCutter the hair cutter
*
* @return self
*/
protected function setHairCutter($hairCutter)
{
$this->hairCutter = $hairCutter;
return $this;
}
}
私のconfigが、これはこれをやっている理由いずれかを知っていますので、
<?php
return [
'managers' => [
'default' => [
'dev' => env('APP_DEBUG'),
'meta' => env('DOCTRINE_METADATA', 'annotations'),
'connection' => env('DB_CONNECTION', 'sqlite'),
'namespaces' => [
'app'
],
'paths' => [
env('COMPASS_ENTITIES',base_path('vendor/apiarchitect/compass/src/Entities')),
env('AUTH_ENTITIES',base_path('vendor/apiarchitect/auth/src/Entities')),
env('LOG_ENTITIES',base_path('vendor/apiarchitect/log/src/Entities')),
env('NODE_ENTITIES',base_path('vendor/jkirkby91/lumendoctrinecomponent/src/Entities')),
env('APP_ENTITIES',base_path('/app/Entities')),
],
'repository' => Doctrine\ORM\EntityRepository::class,
'proxies' => [
'namespace' => false,
'path' => storage_path('proxies'),
'auto_generate' => env('DOCTRINE_PROXY_AUTOGENERATE', false)
],
'events' => [
'listeners' => [],
'subscribers' => []
],
'filters' => [],
'mapping_types' => [
'enum' => 'string'
]
]
],
'extensions' => [
LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class,
LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class,
LaravelDoctrine\Extensions\Loggable\LoggableExtension::class,
LaravelDoctrine\Extensions\Blameable\BlameableExtension::class,
LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class,
LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class,
'custom_types' => [
'json' => LaravelDoctrine\ORM\Types\Json::class
],
'custom_datetime_functions' => [],
'custom_numeric_functions' => [],
'custom_string_functions' => [],
'logger' => env('DOCTRINE_LOGGER', trrue),
'cache' => [
'default' => env('DOCTRINE_CACHE', 'memcached'),
'namespace' => null,
'second_level' => false,
],
'gedmo' => [
'all_mappings' => false
],
'doctrine_presence_verifier' => true,
];
のように見えますか?
私は実際にそれが違いを生むことを期待していませんが、あなたは 'やった - > getRepository( 'アプリケーション\エンティティ\ showOff ') ' - > getRepository(' App \ Entities \ ShowOff ')'(大文字の 'S')を実行すると、何も変わりません。 – Wilt
'showResponse'メソッドの内部ではどうなりますか? 'app() - > make( 'em') - > getRepository( 'App \ Entities \ showOff') - > findAll()'は何を返しますか? – Wilt