<?php

namespace ScnSocialAuth\Mapper;

use ZfcBase\Mapper\AbstractDbMapper;
use Zend\Stdlib\Hydrator\HydratorInterface;

class UserProvider extends AbstractDbMapper implements UserProviderInterface
{
    protected $tableName  = 'user_provider';

    public function findUserByProviderId($providerId, $provider)
    {
        $select = $this
            ->getSelect()
            ->from($this->tableName)
            ->where(
                array(
                    'provider_id' => $providerId,
                    'provider' => $provider,
                )
            );

        $entity = $this->select($select)->current();
        $this->getEventManager()->trigger('find', $this, array('entity' => $entity));

        return $entity;
    }

    public function insert($entity, $tableName = null, HydratorInterface $hydrator = null)
    {
        return parent::insert($entity, $tableName, $hydrator);
    }
}

<?php

namespace ScnSocialAuth\Mapper;

use ZfcBase\Mapper\AbstractDbMapper;
use Zend\Stdlib\Hydrator\HydratorInterface;

class UserProvider extends AbstractDbMapper implements UserProviderInterface
{
    protected $tableName  = 'user_provider';

    public function findUserByProviderId($providerId, $provider)
    {
        $sql    = $this->getSql();
        $select = $sql->select();
        $select->from($this->tableName)
               ->where(array(
                   'provider_id' => $providerId,
                   'provider'    => $provider,
               ));

        $entity = $this->select($select)->current();
        $this->getEventManager()->trigger('find', $this, array('entity' => $entity));

        return $entity;
    }

    public function insert($entity, $tableName = null, HydratorInterface $hydrator = null)
    {
        return parent::insert($entity, $tableName, $hydrator);
    }
}

Fix issue with "readonly" table
Fix issue with "readonly" table

- Using getSelect() was leading to an issue against current ZF2 master whereby
  the table was being marked as readonly; this meant that later calling from()
  led to an exception. This patch fixes that issue by pulling the select() from
  a Sql object and then calling setTable().
