AndyB
Well-known member
I have the following query which works fine:
I would like to use a finder to replace it.
My Entity
In my controller I have the following PHP code:
I'm getting the following error:
What am I doing wrong?
Thank you.
PHP:
$attendees = $db->fetchAll("
SELECT xf_andy_rsvp_register.user_id,
xf_andy_rsvp_register.thread_id,
xf_andy_rsvp_register.guest_count,
xf_andy_rsvp_register.note,
xf_user.username
FROM xf_andy_rsvp_register
INNER JOIN xf_user ON xf_user.user_id = xf_andy_rsvp_register.user_id
WHERE xf_andy_rsvp_register.thread_id = ?
ORDER BY xf_andy_rsvp_register.rsvp_register_id ASC
", $threadId);
I would like to use a finder to replace it.
My Entity
PHP:
<?php
namespace Andy\Rsvp\Entity;
use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;
class RsvpRegister extends Entity
{
public static function getStructure(Structure $structure)
{
$structure->table = 'xf_andy_rsvp_register';
$structure->shortName = 'Andy\Rsvp:RsvpRegister';
$structure->primaryKey = 'rsvp_register_id';
$structure->columns = [
'rsvp_register_id' => ['type' => self::UINT, 'autoIncrement' => true, 'nullable' => true],
'user_id' => ['type' => self::UINT, 'required' => true],
'thread_id' => ['type' => self::UINT, 'required' => true],
'guest_count' => ['type' => self::STR, 'maxLength' => 10, 'default' => ''],
'note' => ['type' => self::STR, 'default' => ''],
];
$structure->getters = [];
$structure->relations = [
'User' => [
'entity' => 'XF:User',
'type' => self::TO_ONE,
'conditions' => 'user_id',
'primary' => true
]
];
return $structure;
}
}
In my controller I have the following PHP code:
PHP:
$finder = \XF::finder('Andy\Rsvp:RsvpRegister');
$attendees = $finder
->where('thread_id', $threadId)
->with('XF:User')
->order('rsvp_register_id', 'ASC')->fetch();
I'm getting the following error:
Code:
LogicException: Unknown relation XF:User accessed on xf_andy_rsvp_register in src/XF/Mvc/Entity/Finder.php at line 630
[LIST=1]
[*]XF\Mvc\Entity\Finder->join() in src/XF/Mvc/Entity/Finder.php at line 572
[*]XF\Mvc\Entity\Finder->with() in src/addons/Andy/Rsvp/XF/Pub/Controller/Thread.php at line 109
[*]Andy\Rsvp\XF\Pub\Controller\Thread->actionIndex() in src/XF/Mvc/Dispatcher.php at line 249
[*]XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 88
[*]XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
[*]XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1844
[*]XF\App->run() in src/XF.php at line 328
[*]XF::runApp() in index.php at line 13
[/LIST]
What am I doing wrong?
Thank you.