我有文章和类别实体。 该实体与映射无关,但是我需要使用查询生成器将Category链接到Article,结果我需要在Category实体中注入Article实体。我该怎么办?
我搜索了Google但没有找到解决方法
class ArticleRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Article::class);
}
public function getAll()
{
$query = $this->createQueryBuilder('articles')
->select('articles, category')
->join(\App\Entity\Category::class, 'category', 'WITH', 'articles.categoryId = category.id')
->getQuery();
echo '<pre>';
print_r($query->getResult());
exit;
}
?>
// output
Array
(
[0] => App\Entity\Article Object
(
[id:App\Entity\Article:private] => 1
[name:App\Entity\Article:private] => title1
[text:App\Entity\Article:private] => text1
[categoryId:App\Entity\Article:private] => 1
[categories:App\Entity\Article:private] =>
)
[1] => App\Entity\Category Object
(
[id:App\Entity\Category:private] => 1
[name:App\Entity\Category:private] => first cat
)
[2] => App\Entity\Article Object
(
[id:App\Entity\Article:private] => 2
[name:App\Entity\Article:private] => title2
[text:App\Entity\Article:private] => text2
[categoryId:App\Entity\Article:private] => 1
[categories:App\Entity\Article:private] =>
)
[3] => App\Entity\Article Object
(
[id:App\Entity\Article:private] => 3
[name:App\Entity\Article:private] => title3
[text:App\Entity\Article:private] => text3
[categoryId:App\Entity\Article:private] => 2
[categories:App\Entity\Article:private] =>
)
[4] => App\Entity\Category Object
(
[id:App\Entity\Category:private] => 2
[name:App\Entity\Category:private] => second cat
)
)
答案 0 :(得分:0)
尝试以下方式:
n = 10
pd.Series(range(1, n+1), dtype=str).str.zfill(3).radd('VAL')
0 VAL001
1 VAL002
2 VAL003
3 VAL004
4 VAL005
5 VAL006
6 VAL007
7 VAL008
8 VAL009
9 VAL010
dtype: object
代替
n=500