Zum Inhalt springen

Extbase Record Relation von eigener Tabelle zu tt_content

Erstellt am 27. Juli 2011 · 6 Antworten · letzte Antwort am 1. Mai 2012

Tags: Inhaltselemente, Frage

aemka ·

Hi,

Ich bin gerade an meinem ersten Extbase Projekt. Ich habe Project Datensätze, die tt_content Elemente enthalten. So weit so gut. Da man Core-Tabellen wie tt_content im EXT:extension_kickstarter nicht mit eigenen Tabellen verbinden kann, habe ich erst mal eine Dummy Tabelle "content" im Extbase Kickstarter angelegt und diese mit dem Projekt verbunden und dann im TCA und Typoscript die Tabelle meines Content-Models wieder auf tt_content geändert. Im Backend kann man problemlos tt_content Elemente über IRRE dem Projekt zuordnen. Aber wenn ich die Content Elemente im Fluid-Template ausgeben will, behauptet das Projekt Model, es hätte keine Content-Elemente in seinem ObjectStorage.

Classes/Domain/Model/Project.php:

class Tx_Nhb_Domain_Model_Project extends 
Tx_Extbase_DomainObject_AbstractEntity {

...

	/**
	 * Content
	 *
	 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Nhb_Domain_Model_Content> $content
	 */
	protected $content;

...

	/**
	 * Returns the content
	 *
	 * @return Tx_Extbase_Persistence_ObjectStorage<Tx_Nhb_Domain_Model_Content> $content
	 */
	public function getContent() {
		return $this->content;
	}

...

}

Classes/Domain/Model/Content.php:

class Tx_Nhb_Domain_Model_Content extends Tx_Extbase_DomainObject_AbstractValueObject {

	/**
	 * __construct
	 *
	 * @return void
	 */
	public function __construct() {

	}

}

Typoscript:

plugin.tx_nhb {
	persistence {
		classes {
			Tx_Nhb_Domain_Model_Content {
				mapping {
					tableName = tt_content
					recordType = Tx_Nhb_Domain_Model_Content
					columns {
					}
				}
			}
		}
	}
}

TCA:

$TCA['tx_nhb_domain_model_project'] = array(
...
	'columns' => array(
...
		'content' => array(
			'exclude' => 0,
			'label' => 'LLL:EXT:nhb/Resources/Private/Language/locallang_db.xml:tx_nhb_domain_model_project.content',
			'config' => array(
				'type' => 'inline',
				'foreign_table' => 'tt_content',
				'foreign_field' => 'project',
				'maxitems'      => 9999,
				'appearance' => array(
					'collapse' => 0,
					'levelLinksPosition' => 'top',
					'showSynchronizationLink' => 1,
					'showPossibleLocalizationRecords' => 1,
					'showAllLocalizationLink' => 1
				),
			),
		),

...

),
);

SQL:

CREATE TABLE tt_content (
	project int(11) unsigned DEFAULT '0' NOT NULL
);

ext_tables.php:

t3lib_div::loadTCA('tt_content');
$TCA['tt_content']['columns']['project']['config']['type'] = 'passthrough';

$this->content in class Classes/Domain/Model/Project.php ist immer leer, obwohl das Project in der Datenbank 3 tt_content elemente zugeordnet hat.

In mysql steht tx_nhb_domain_model_project.content (id: 1) auf 3 und die zugeordneten tt_content Elemente (ids: 15, 14, 13) haben alle tt_content.project auf 1 stehen. Das ist beides korrekt gespeichert.

In Fluid versuche ich nur mal die uids der Elemente auszugeben:

<f:for each="{project.content}" as="content">
  {content.uid}<br />
</f:for>

Eigentlich kann nur eine Kleinigkeit falsch sein, aber ich finde keine Doku für diesen etwas abgefahrenen Fall, die mir das klar macht, was hier falsch sein könnte.

Eydamos ·

Ist dein Feld projekt überhaupt in der tt_content Tabelle angelegt worden?

Dein SQL Statement ist nämlich falsch mit CREATE TABLE würde die Datenbank versuchen die Tabelle tt_content zu erstellen und mit einer Fehlermeldung aussteigen da sie schon existiert.

Richtig wäre es:

ALTER TABLE tt_content ADD (
	project int(11) UNSIGNED DEFAULT '0' NOT NULL
);
aemka ·

Das Feld ist angelegt und ist gefüllt. Die Syntax ist so für den das Database Compare des TYPO3 Core schon richtig.

aemka ·

Ein netter Mensch aus der Newsgroup hat es gelöst:

Das recordType Setting im TS musste weg, dann geht es.

Erklärung:

---
If you are setting the recordType in above TS then you must have a field
defined by $TCA['tt_content']['ctrl']['type'] in tt_content which in
your case is already present "CType".

So you just need to set the value of this field (tt_content.CType) to
'Tx_Nhb_Domain_Model_Content' and then hopefully it should work OR
remove the recordType setting from above TS 😉
---

MorphexX ·

Danke für den Thread - er passt fast genau auf mein aktuelles Problem.
Allerdings habe ich dein Setup gegen meines gehalten und übernommen, habe jedoch immer noch Schwierigkeiten.

Ich erhalte beim Zugriff auf project.content / content.uid in einer for each-Schleife, folgende Exception:

#1247602160: Table 't3extdev.tx_extname_domain_model_content' doesn't exist: SELECT COUNT(*) FROM tx_extname_domain_model_content WHERE tx_extname_domain_model_content.project = '5' (More information)

Und ich habe bereits die Persistenz-Schicht im TS umgemapped. Ich bin gerade etwas ratlos.

Ich bin für jede Hilfe dankbar.

MorphexX ·

Einen ganz herzlichen Dank, aemka! Voll ins Schwarze!

Das statische Extension Template war nicht mehr eingebunden, nachdem ich ein paar String Replacements bzgl. des Extension-Namen vorgenommen habe.

Erneut eingebunden - alles gut! 🙂