Hmm - 基本的な質問のように見えますが、既に回答済みです。しかし、あなたのセットアップは私に少しバグがあります...
私はあなたのテーブルを少し改造したいと思います(国際化は問題ではないと仮定します)。とりわけ、私は「カテゴリー」と「ギャラリー」という概念の根本的な違いがあるとは感じていません。現在、「スーパー」と「サブ」のカテゴリ/ギャラリーがあり、イメージは一度に複数のものに属している場合があります(つまり、レナジアンス、ミケランジェロ、彫刻など)。これはタグの概念に似ています。
私はおそらくのようなものに、あなたのテーブルを修正したい:
Gallery (or Category, if you prefer)
=============
id -- autoincrement
name -- varchar(50) or something, unique
parent -- fk reference to another Gallery.id row, optional
Image
==========
id -- autoincrement
name -- varchar(50) or similar, non-unique
path -- store as URI/URL, unique
description -- varchar(128) or similar
Gallery_Image
===============
galleryId -- fk reference to Gallery.id
imageId -- fk reference to Image.id
-- the pair is unique
Related_Gallery -- optional table
================
galleryId -- fk reference to Gallery.id
relationship -- code, or fk reference to other table
relatedId -- fk reference to Gallery.id
-- entire row should be unique
-- somewhat tricky to use.
私はこれを試してみましたが、このクエリは関係なく、ギャラリーがイメージを持っているか、いない場合は、最新のギャラリーを選択していない:「NewsAdminBundleからのPを選択:ギャラリーP P .category_id =:カテゴリとp.id IN(SELECT i FROM NewsAdminBundle:GalleryImages i)ORDER BY p.created_at DESC ' – repincln