Extbase毫米关系-对面的吸气剂

时间:2019-02-04 10:44:25

标签: typo3 extbase

我有两个实体:

课程和 期间

两者都可以通过联接表链接。在TCA课程中,期间定义为内联,因此我可以为每个课程添加新的期间。这些条目正确存储在联接表中。在课程TCA上,正确显示了链接的“期间”。当我通过PeriodRepository获得一个期间并尝试按每个期间获取课程时,结果为空。如何按期访问课程?

TCA课程:

 'periods'              => [
        'exclude' => true,
        'label'   => 'LLL:EXT:courses/Resources/Private/Language/locallang_db.xlf:tx_courses_domain_model_period',
        'config'  => [
            'type'                             => 'inline',
            'foreign_table'                    => 'tx_courses_domain_model_period',
            'MM'                               => 'tx_courses_course_period_mm',
            'enableMultiSelectFilterTextfield' => true,
            'MM_opposite_field'                => 'courses',
            'appearance'                       => [
                'useSortable'  => 1,
                'collapseAll'  => 1,
                'expandSingle' => 1,
            ]
        ],

    ],

TCA期限:

        'courses'          => [
        'exclude' => true,
        'label'   => 'LLL:EXT:courses/Resources/Private/Language/locallang_db.xlf:tx_courses_domain_model_module.courses',
        'config'  => [
            'type'              => 'select',
            'multiple'          => 1,
            'foreign_table'     => 'tx_courses_domain_model_course',
            'MM'                => 'tx_courses_course_period_mm',
            'MM_opposite_field' => 'periods',
        ],

    ],

实体课程:

/**
 * periods
 *
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\NAMESPACE\courses\Domain\Model\Period>
 */
protected $periods = null;

/**
 * Adds a Period
 *
 * @param \NAMESPACE\courses\Domain\Model\Period $period
 *
 * @return void
 */
public function addPeriod(\NAMESPACE\courses\Domain\Model\Period $period)
{
    $this->periods->attach($period);
}

/**
 * Removes a Period
 *
 * @param \NAMESPACE\courses\Domain\Model\Period $periodToRemove The Period to be removed
 *
 * @return void
 */
public function removePeriod(\NAMESPACE\courses\Domain\Model\Period $periodToRemove)
{
    $this->periods->detach($periodToRemove);
}

/**
 * Returns the periods
 *
 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\NAMESPACE\courses\Domain\Model\Period> $periods
 */
public function getPeriods()
{
    return $this->periods;
}

/**
 * Sets the periods
 *
 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\NAMESPACE\courses\Domain\Model\Period> $periods
 *
 * @return void
 */
public function setPeriods(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $periods)
{
    $this->periods = $periods;
}

实体有效期:

/**
 * modules
 *
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\NAMESPACE\courses\Domain\Model\Course>
 */
protected $courses = null;

/**
 * Adds a Course
 *
 * @param \NAMESPACE\courses\Domain\Model\Course $course
 *
 * @return void
 */
public function addCourse(\NAMESPACE\courses\Domain\Model\Course $course)
{
    $this->courses->attach($course);
}

/**
 * Removes a Course
 *
 * @param \NAMESPACE\courses\Domain\Model\Course $courseToRemove The Course to be removed
 *
 * @return void
 */
public function removeCourse(\NAMESPACE\courses\Domain\Model\Course $courseToRemove)
{
    $this->courses->detach($courseToRemove);
}

/**
 * Returns the courses
 *
 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\NAMESPACE\courses\Domain\Model\Course> $courses
 */
public function getCourses()
{
    return $this->courses;
}

/**
 * Sets the courses
 *
 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\NAMESPACE\courses\Domain\Model\Course> $courses
 *
 * @return void
 */
public function setCourses(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $courses)
{
    $this->courses = $courses;
}

迁移:

CREATE TABLE tx_courses_domain_model_course (
    title varchar(255) DEFAULT '' NOT NULL,
    periods int(11) unsigned DEFAULT '0' NOT NULL,
);

CREATE TABLE tx_courses_domain_model_period (

    title varchar(255) DEFAULT '' NOT NULL,
  courses int(11) unsigned DEFAULT '0' NOT NULL,
);

CREATE TABLE tx_courses_course_period_mm (
    uid_local int(11) unsigned DEFAULT '0' NOT NULL,
    uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
    sorting int(11) unsigned DEFAULT '0' NOT NULL,
    sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL,
    KEY uid_local (uid_local),
    KEY uid_foreign (uid_foreign)
);

0 个答案:

没有答案