TYPO3 Extbase双向1:n关系 [英] TYPO3 Extbase bidirectional 1:n relation

查看:74
本文介绍了TYPO3 Extbase双向1:n关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们在AuthorBook模型之间具有1:n关系.使用扩展构建器对关系进行建模,提供了为作者获取Book所需的代码.

Let's say we have a 1:n relation between an Author and Book model. Modeling the relation using the Extension Builder, the necessary code to get Book's for an author is provided.

但是反之类的呢?如何获得给定Book类的Author?

But what about the inverse? How do I get the Author for a given Book class?

推荐答案

我假定您已经使用扩展构建器创建了以下域模型.

I assume you have created the following domain model with the Extension Builder.

在Author和Book之间创建1:n关系时,Book的结果数据库表将包含一个保存作者UID的字段.要使用此字段,您必须在书域模型中添加 getter ,以返回给定书的相应作者.

When you create a 1:n relation between Author and Book, the resulting database table for Book will contain a field which holds the UID of the author. To make use of this field, you have to add a getter in your book domain model to return the corresponding author for the given book.

将以下内容添加到您的图书领域模型中:

Add the following to your domain model for book:

/**
 * Returns the author
 *
 * @var \TYPO3\YourExtension\Domain\Model\Author
 */
protected $author;

/**
 * @return \TYPO3\YourExtension\Domain\Model\Author
 */
public function getAuthor() {
    return $this->author;
}

现在,您可以在Fluid中使用新的getter来使用{book.author}

Now you can use the new getter in Fluid to return the author of a given book with {book.author}

这篇关于TYPO3 Extbase双向1:n关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆