esensi / model

The base model traits of Esensi
MIT License
202 stars 25 forks source link

Esensi Model With Sentry 2 #15

Closed kodeine closed 9 years ago

kodeine commented 9 years ago

Could you please share validation for sentry 2? I added Traits but Sentry seems to use its own validator. any help would be appreciated.

dalabarge commented 9 years ago

@ahsenx we do not use Sentry 2 so we don't have any insights to share with you. If you do figure out a configuration that works or can share some code that you are trying to get to work I'll see if I can point you in the right direction. Fundamentally Esensi/Model uses traits to customize and sometimes overwrite Eloquent/Model. Sentry 2 might also be doing the same thing, so to implement our interfaces and also implement Sentry 2's capabilities it might be necessary to write custom traits for some of the functionality. If you figure out a working trait please propose a pull request so we can provide a Sentry compatible trait.

kodeine commented 9 years ago

@dalabarge I will work on it and propose a PR. Also would it be possible to use esensi/model along with jenssegers/laravel-mongodb? I was just thinking it would be easier to implement but since you know esensi model more, you can give me your insight.

dalabarge commented 9 years ago

The major feature of esensi/model is the ValidatingModelTrait which integrates mainly with model attributes, getters/setters and of course the validation service of Laravel. Another trait often used is the RelatingModelTrait which deals with the many types of relationships. Moloquent (as it is aliased in documentation) has slightly different fluent methods than Eloquent and so the traits might need to be modified somewhat to make it work. I would venture to say that 90% of the trait logic should work as is and 100% of the interfaces. So with that said, include each interface on your Moloquent model as needed then include the corresponding traits. If one of the trait methods is failing you just need to identify the conflict code and resolve it manually using a custom trait: this custom trait only needs to have the necessary methods to overwrite the esensi/model trait methods.

Again, we're very much open to PRs so please submit any findings you make as a PR or at least as a code sample in a comment - that would be very helpful to ensuring others also can use Mongo that with this package.

kodeine commented 9 years ago

@dalabarge hello again, I was able to figure out the validation based on Moloquent. I made a moloquent repo trait which had common functions for other models. In the trait i added two functions which sets the Validator Database connection to moloquent. No other change was needed. I override getConnection() just in case model itself does not have $connection string so including just the trait would take care of it.

trait MoloquentRepositoryTrait
{
    protected $connectionName = 'mongodb';

    /*
     * Helper Function for Moloquent
     * Sets mongodb connection
     * Since $connection is protected string.
     * We have to override the function to use
     * mongodb as a connection if its not defined
     * model.
     */
    public function getConnection()
    {
        if ($this->connection != 'mongodb') {
            $this->DatabasePresenceVerifier();
            parent::setConnection($this->connectionName);
        }
        return parent::getConnection();
    }

    protected function DatabasePresenceVerifier()
    {
        return \Validator::getPresenceVerifier()->setConnection($this->connectionName);
    }