• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

DataWriter for Relation-Like Database Table


Well-known member

I've created a relation table for an AddOn of the following form:

I'm trying to update the table with my DataWriter, but I end up either creating a duplicate entry or getting the following error:
  • The existing data required by the data writer could not be found.
  • Please enter a value for the required field 'resource_id'.
  • Please enter a value for the required field 'member_id'.
My DataWriter:

class ResourceToRPG_DataWriter_RPGMember extends XenForo_DataWriter {
    protected function _getFields() {
        return array(
            'xf_rtr_members' => array(
                'id'            => array('type' => self::TYPE_UINT, 'autoIncrement' => true),
                'resource_id'   => array('type' => self::TYPE_UINT, 'required' => true),
                'member_id'     => array('type' => self::TYPE_UINT, 'required' => true),
                'status'  => array('type' => self::TYPE_STRING, 'default' => 'Approved',
                    'allowedValues' => array('Approved', 'Unapproved', 'Moderator')
    protected function _getExistingData($data)
        if (!is_array($data))
            return false;
        else if (isset($data['member_id'], $data['resource_id']))
            $memberId = $data['member_id'];
            $resourceId = $data['resource_id'];
            return false;

        return array('xf_rtr_members' => $this->_getResourceModel()->getMemberState($memberId, $resourceId));
    protected function _getUpdateCondition($tableName) {
        return 'resource_id = '.$this->_db->quote($this->getExisting('resource_id')).
                ' AND member_id = '.$this->_db->quote($this->getExisting('member_id'));
    protected function _getResourceModel() {
        return $this->getModelFromCache('XenResource_Model_Resource');
The getMemberStatus-Function in the Model:
    public function getMemberState($idr,$idu) {
        return $this->_getDb()->fetchRow('
            SELECT *
            FROM xf_rtr_members
            WHERE member_id = ?
            AND resource_id = ?

        ', array(
And the snippet of the Save-Call in the ControllerPublic:
        $resource['resource_id'] = $this->_input->filterSingle('rid', XenForo_Input::UINT);
        $users = $this->_input->filterSingle('user_ids', XenForo_Input::ARRAY_SIMPLE);
        $action = $this->_input->filterSingle('do', XenForo_Input::STRING);
        $dw = XenForo_DataWriter::create('ResourceToRPG_DataWriter_RPGMember');
        //Define Action
        switch($action) {
            case 'approve':
                foreach($users as $user) {
                    $data = array('resource_id' => $resource['resource_id'], 'member_id' => $user);
Someone has a hint for me where my mistake lies?


Well-known member
Wow, this is so awkward...
I've called "public function getMemberState($idr,$idu)" with the wrong parameter order...
Guess the topic can be closed. :oops: