Giter Site home page Giter Site logo

laravel-custom-relation's People

Contributors

danielmorgan avatar hosseynjf avatar johnnyfreeman avatar lovemhz avatar nerdo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-custom-relation's Issues

Call to undefined method Illuminate\Database\Query\Builder::buildDictionary()

This package is exactly what i need. Unfortunately, I am getting this error:

Call to undefined method Illuminate\Database\Query\Builder::buildDictionary()

in Builder.php line 2448
at Builder->__call('buildDictionary', array(object(Collection)))
at Builder->buildDictionary(object(Collection))
at call_user_func_array(array(object(Builder), 'buildDictionary'), array(object(Collection))) in Builder.php line 1467
at Builder->__call('buildDictionary', array(object(Collection)))
at Builder->buildDictionary(object(Collection))
at call_user_func_array(array(object(Builder), 'buildDictionary'), array(object(Collection))) in Relation.php line 344
at Relation->__call('buildDictionary', array(object(Collection))) in Custom.php line 90
at Custom->buildDictionary(object(Collection)) in Custom.php line 90
at Custom->match(array(object(Category)), object(Collection), 'descendants') in Builder.php line 687
at Builder->loadRelation(array(object(Category)), 'descendants', object(Closure)) in Builder.php line 654
at Builder->eagerLoadRelations(array(object(Category))) in Builder.php line 333
at Builder->get(array('')) in Builder.php line 297
at Builder->first(array('
')) in Builder.php line 171
at Builder->find('1') in GroupController.php line 21

Doesn't work with morph relation

if (isset($dictionary[$key = $model->getKey()])) {

Compare works only with the fields that exists in a model. By the way morph match does like this:

if (isset($dictionary[$key = $model->getAttribute($this->localKey)])) {

Could u add possibility to define keys?

Api Proposal

Now that #8 has been merged, I feel like we've learned the best way to tackle the issue of making a custom relation is by accepting callables/closures for the abstract Relation methods rather than trying to find an implementation that fits every scenario. I don't like the readability of it though...

class User extends Model
{
    use HasCustomRelations;

    public function someOtherRelation()
    {
        return $this->custom(
            SomeOtherModel::class,
            function (...) {
                // ...
            },
            function (...) {
                // ...
            },
            function (...) {
                // ...
            },
            function (...) {
                // ...
            },
        );
    }
}

Seems cluttered and I forget which Closure is which and have to reference the package. The introduction of a new RelationBuilder object might be helpful for readability. Something like this...

class User extends Model
{
    use HasCustomRelations;

    public function someOtherRelation()
    {
        return $this->buildRelation()
            ->related(SomeOtherModel::class)
            ->addConstraints(function (...) {
                // ...
            })
            ->addEagerConstraints(function (...) {
                // ...
            })
            ->initRelation(function (...) {
                // ...
            })
            ->match(function (...) {
                // ...
            })
            ->getRelation();
    }
}

While I like this better, my question now becomes, is this any better than just creating a new class that for each custom relation? Then you can just do this.

class User extends Model
{
    use HasCustomRelations;

    public function someOtherRelation()
    {
        return new MyCustomRelation(SomeOtherModel::query(), $this);
    }
}

I guess on one hand you would have potentially a large amount of custom classes/files that just describe a single custom relationship, and on the other hand, you have a potentially large amount of these verbose RelationBuilder methods on your models.

Maybe there's room for both? What are your thoughts?

laravel-custom-relation not installing on laravel 7.28.3

after trying installing this package with compser:

php composer.phar require "johnnyfreeman/laravel-custom-relation"

I get this:

Using version ^0.0.3 for johnnyfreeman/laravel-custom-relation
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for johnnyfreeman/laravel-custom-relation ^0.0.3 -> satisfiable by johnnyfreeman/laravel-custom-relation[0.0.3].
    - Conclusion: remove laravel/framework v7.28.3
    - Conclusion: don't install laravel/framework v7.28.3
    - johnnyfreeman/laravel-custom-relation 0.0.3 requires laravel/framework ^5.2.0 -> satisfiable by laravel/framework[5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev].
    - Can only install one of: laravel/framework[5.5.x-dev, v7.28.3]. 
    - Can only install one of: laravel/framework[5.6.x-dev, v7.28.3]. 
    - Can only install one of: laravel/framework[5.7.x-dev, v7.28.3]. 
    - Can only install one of: laravel/framework[5.8.x-dev, v7.28.3]. 
    - Can only install one of: laravel/framework[5.2.x-dev, v7.28.3]. 
    - Can only install one of: laravel/framework[5.3.x-dev, v7.28.3]. 
    - Can only install one of: laravel/framework[5.4.x-dev, v7.28.3]. 
    - Installation request for laravel/framework (locked at v7.28.3, required as ^7.0) -> satisfiable by laravel/framework[v7.28.3].


Installation failed, reverting ./composer.json to its original content.

so is there any fix to this?

btw thanks I just copy-pasted version 3 into my manually app. but with composer, updates are a lot easier.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.