Code Monkey home page Code Monkey logo

Comments (7)

jpfuentes2 avatar jpfuentes2 commented on September 26, 2024

Initially, we were considering using PHP's ArrayObject for a collection returned form the database, but we decided not to because of the overhead involved. If someone wanted to provide some benchmarks that shows a large performance hit is not incurred when using ArrayObject, then we could implement the feature.

from php-activerecord.

greut avatar greut commented on September 26, 2024

I think this would provide a lot of flexibility. See my hack there: https://github.com/greut/php-activerecord/blob/relation_count/lib/Relationship.php#L453-470

from php-activerecord.

greut avatar greut commented on September 26, 2024

Can you please go through this?

greut@1383d64

Cheers,

from php-activerecord.

greut avatar greut commented on September 26, 2024

What about this?

<?php
class Person extends ActiveRecord\Model
{
    static $has_many = array(
        array('addresses')
    );
}

$person = Person::find(1);
// all the addresses, no hit on the DB. (obj1)
$addresses = $person->addresses;
// the last five addresses, no hit on the DB (obj2)
$addresses = $addresses(array('limit' => 5, 'order' => 'id desc'));
// hits the DB and cache the result
var_dump($addresses[0]);

obj1 and obj2 are two different objects, so calling it results in creating a modified copy.

from php-activerecord.

nakashu avatar nakashu commented on September 26, 2024

little resurrection .

Could this be merged into master ?
This will greatly benefit, in all poly relations.

If there are anything thats missing, before it can be merged, I'll try to find the time to finish it.
Btw, would it be possible to implement it same as ruby with .. find / where on the collection ?

from php-activerecord.

al-the-x avatar al-the-x commented on September 26, 2024

@nakashu See #108, which introduces a fix for this. We're looking at pulling it into v1.1 ATM. Thanks for the ping!

from php-activerecord.

jpfuentes2 avatar jpfuentes2 commented on September 26, 2024

closing in favor of #376

from php-activerecord.

Related Issues (20)

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.