Ability to return extended PropelObjectCollection from query?

Showing 1-10 of 10 messages
Ability to return extended PropelObjectCollection from query? Lee Leathers 10/18/12 12:41 AM
Is there a way to return an extended class of PropelObjectCollection unique to the base class instead of the PropelObjectCollection default?

Quick Usages:
$invoices = InvoiceQuery::create()->find();

# custom method from InvoiceObjectCollection
echo $invoices->sumAmount();

# gist of InvoiceObjectCollection


Can Propel be told to do this explicitly or implicitly from introspection of the lib/model/collection/ folder?

If there isn't a way to do this, would anyone be interested in me whipping something up and submitting a pull request on master?

- Lee
Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Marius Ghita 10/18/12 8:53 AM
I think you should be able to extend the PropelObjectFormatter, in this extended class change the protected property $collectionName to InvoiceObjectCollection and use setFormatter on the query.

Maybe even overwrite the create method on the InvoiceQuery class in order to preset each query with this new formatter.

Once wanted to write a behavior to do this, but drifted away. Maybe you'll do just that :)


- Lee

--
You received this message because you are subscribed to the Google
Groups "Propel Development" group.
To post to this group, send email to propel-de...@googlegroups.com
To unsubscribe from this group, send email to
propel-development+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/propel-development



--
Google+: https://plus.google.com/111881868112036203454

Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Lee Leathers 10/18/12 12:29 PM
Very sexy direction. I like this, and to go the next step for me would be to have the $collectionName dynamic on this new extended class.

Maybe by way of dependency injection?

->setFormatter(new CustomObjectFormatter($this->getPackage()))

and then add we can add the behavior on top of this for nearly full automation. We would just need to get the setFormatter API updated to take string| CustomObjectFormatter

thoughts?

--
Lee Leathers
about.me/leeleathers
706-340-7424


On Thursday, October 18, 2012 at 8:53 AM, Marius Ghita wrote:

> I think you should be able to extend the PropelObjectFormatter, in this extended class change the protected property $collectionName to InvoiceObjectCollection and use setFormatter on the query.
>
> Maybe even overwrite the create method on the InvoiceQuery class in order to preset each query with this new formatter.
>
> Once wanted to write a behavior to do this, but drifted away. Maybe you'll do just that :)
>
> On Thu, Oct 18, 2012 at 10:41 AM, Lee Leathers <leele...@gmail.com (mailto:leele...@gmail.com)> wrote:
> >  Is there a way to return an extended class of PropelObjectCollection unique to the base class instead of the PropelObjectCollection default?
> >
> > Quick Usages:
> > $invoices = InvoiceQuery::create()->find();
> >
> > # custom method from InvoiceObjectCollection
> > echo $invoices->sumAmount();
> >
> > # gist of InvoiceObjectCollection
> > https://gist.github.com/3910303
> >
> >
> > Can Propel be told to do this explicitly or implicitly from introspection of the lib/model/collection/ folder?
> >
> > If there isn't a way to do this, would anyone be interested in me whipping something up and submitting a pull request on master?
> >
> > - Lee
> >
> >  --
> >  You received this message because you are subscribed to the Google
> >  Groups "Propel Development" group.
> >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> >  To unsubscribe from this group, send email to
> > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com)
> >  For more options, visit this group at
> > http://groups.google.com/group/propel-development
>
>
> --
> Google+: https://plus.google.com/111881868112036203454
>
>  --
>  You received this message because you are subscribed to the Google
>  Groups "Propel Development" group.
>  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
>  To unsubscribe from this group, send email to
> propel-development+unsubscribe@googlegroups.com (mailto:propel-development+unsubscribe@googlegroups.com)
Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Marius Ghita 10/18/12 3:15 PM
Maybe something along the lines to use Propel's consistency model, and generator friendly.

class ModelObjectFormatter {

  protected $formatter;
  protected $exists;

  public function __construct($modelClass) {
    $peer  = $modelClass::PEER;
    $model = $peer::OM_CLASS;

    $this->formatter = $model.'ObjectFormatter';
    $this->exists    = class_exists($this->formatter);
  }

  public function __toString() {
    if(false === $this->exists) {
      throw new InvalidArgumentException(sprintf(
        "No such formatter class found: %s",
        $this->formatter
      );
    }

    return $this->formatter;
  }

  public function doesExist() {
    return $this->exists;
  }
}

And afterwards in your create method overwrite

  public function __construct($modelAlias = null, $criteria = null) {
    $query     = parent::create($modelAlias, $criteria);
    $formatter = new ModelObjectFormatter($query->getModelName());

    return $query->setFormatter(
      $formatter->doesExist() ? (string)$formatter : 'PropelObjectFormatter'
    );
  }

String typecast is necessary because the setFormatter method accepts objects as well, which case would throw an exception due to expected PropelFormatter interface.

The other way around would be to generate these autonamed model object formatters, much like Peer classes; but in my consideration that wouldn't be an ideal, given that in large normalized databases you tend to have quite a few crossReference tables. For which even Peer classes are one file too much.

Hope that helps, and hope to see a github repo out of this. Would beat my lazyness to code up this solution the next time I'll be needed. :)
Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Lee Leathers 10/19/12 2:10 AM
I like it. I was able to get something rolling w/ these ideas.

DynamicCollectionObjectFormatter class

Trait:

then add this to whatever model query class you want:
use DynamicCollectionObjectFormatterTrait;


I used php traits instead of behaviors since we use traits heavily. It would be nice if we could get the DynamicCollectionObjectFormatter in the core. Anyone on the core team interested in this if I provide tests?
Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Francois Zaninotto 10/19/12 2:18 AM
Love it. This should definitely be part of the Propel2.0 core : start working on a pull request!. As for Propel 1.6, I think it's feature freeze, but you can link your extension here: http://www.propelorm.org/cookbook/user-contributed-behaviors.html.

Cheers,

François

2012/10/19 Lee Leathers <leele...@gmail.com>

Re: [propel-dev] Ability to return extended PropelObjectCollection from query? William DURAND 10/19/12 5:36 AM
+1 on this too, please ship it.

William

Le 19 oct. 2012 à 11:17, Francois Zaninotto <fzani...@gmail.com> a écrit :

Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Lee Leathers 10/19/12 11:50 AM
2.0 it is.  

--  
Lee Leathers
about.me/leeleathers
706-340-7424


On Friday, October 19, 2012 at 5:35 AM, William DURAND wrote:

> +1 on this too, please ship it.
>  
> William
>  
> Le 19 oct. 2012 à 11:17, Francois Zaninotto <fzani...@gmail.com (mailto:fzani...@gmail.com)> a écrit :
>  
> > Love it. This should definitely be part of the Propel2.0 core : start working on a pull request!. As for Propel 1.6, I think it's feature freeze, but you can link your extension here: http://www.propelorm.org/cookbook/user-contributed-behaviors.html.
> >  
> > Cheers,
> >  
> > François
> >  
> > 2012/10/19 Lee Leathers <leele...@gmail.com (mailto:leele...@gmail.com)>
> > > > On Thu, Oct 18, 2012 at 10:28 PM, Lee Leathers <leele...@gmail.com (mailto:leele...@gmail.com)> wrote:
> > > > > Very sexy direction. I like this, and to go the next step for me would be to have the $collectionName dynamic on this new extended class.
> > > > >  
> > > > >  Maybe by way of dependency injection?
> > > > >  
> > > > >  ->setFormatter(new CustomObjectFormatter($this->getPackage()))
> > > > >  
> > > > >  and then add we can add the behavior on top of this for nearly full automation. We would just need to get the setFormatter API updated to take string| CustomObjectFormatter
> > > > >  
> > > > >  thoughts?
> > > > >  
> > > > >  --
> > > > >  Lee Leathers
> > > > > about.me/leeleathers (http://about.me/leeleathers)
> > > > > 706-340-7424 (tel:706-340-7424)
> > > > >  
> > > > >  On Thursday, October 18, 2012 at 8:53 AM, Marius Ghita wrote:
> > > > >  
> > > > > > I think you should be able to extend the PropelObjectFormatter, in this extended class change the protected property $collectionName to InvoiceObjectCollection and use setFormatter on the query.
> > > > > >  
> > > > > > Maybe even overwrite the create method on the InvoiceQuery class in order to preset each query with this new formatter.
> > > > > >  
> > > > > > Once wanted to write a behavior to do this, but drifted away. Maybe you'll do just that :)
> > > > > >  
> > > > > > On Thu, Oct 18, 2012 at 10:41 AM, Lee Leathers <leele...@gmail.com (mailto:leele...@gmail.com) (mailto:leele...@gmail.com)> wrote:
> > > > > > > Is there a way to return an extended class of PropelObjectCollection unique to the base class instead of the PropelObjectCollection default?
> > > > > > >  
> > > > > > > Quick Usages:
> > > > > > > $invoices = InvoiceQuery::create()->find();
> > > > > > >  
> > > > > > > # custom method from InvoiceObjectCollection
> > > > > > > echo $invoices->sumAmount();
> > > > > > >  
> > > > > > > # gist of InvoiceObjectCollection
> > > > > > > https://gist.github.com/3910303
> > > > > > >  
> > > > > > >  
> > > > > > > Can Propel be told to do this explicitly or implicitly from introspection of the lib/model/collection/ folder?
> > > > > > >  
> > > > > > > If there isn't a way to do this, would anyone be interested in me whipping something up and submitting a pull request on master?
> > > > > > >  
> > > > > > > - Lee
> > > > > > >  
> > > > > > > --
> > > > > > > You received this message because you are subscribed to the Google
> > > > > > > Groups "Propel Development" group.
> > > > > > > To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com) (mailto:propel-de...@googlegroups.com)
> > > > > > > To unsubscribe from this group, send email to
> > > > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com) (mailto:propel-development%2Bunsubscribe@googlegroups.com (mailto:propel-development%252Bunsubscribe@googlegroups.com))
> > > > > > > For more options, visit this group at
> > > > > > > http://groups.google.com/group/propel-development
> > > > > >  
> > > > > >  
> > > > > > --
> > > > > > Google+: https://plus.google.com/111881868112036203454
> > > > > >  
> > > > > > --
> > > > > > You received this message because you are subscribed to the Google
> > > > > > Groups "Propel Development" group.
> > > > > > To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com) (mailto:propel-de...@googlegroups.com)
> > > > > > To unsubscribe from this group, send email to
> > > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com) (mailto:propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com))
> > > > > > For more options, visit this group at
> > > > > > http://groups.google.com/group/propel-development
> > > > >  
> > > > >  
> > > > >  --
> > > > >  You received this message because you are subscribed to the Google
> > > > >  Groups "Propel Development" group.
> > > > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> > > > >  To unsubscribe from this group, send email to
> > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com)
> > > > >  For more options, visit this group at
> > > > > http://groups.google.com/group/propel-development
> > > >  
> > > >  
> > > >  
> > > > --  
> > > > Google+: https://plus.google.com/111881868112036203454
> > > >  
> > > >  
> > > >  --  
> > > >  You received this message because you are subscribed to the Google
> > > >  Groups "Propel Development" group.
> > > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> > > >  To unsubscribe from this group, send email to
> > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development+unsubscribe@googlegroups.com)
> > > >  For more options, visit this group at
> > > > http://groups.google.com/group/propel-development
> > >  --  
> > >  You received this message because you are subscribed to the Google
> > >  Groups "Propel Development" group.
> > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> > >  To unsubscribe from this group, send email to
> > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com)
> > >  For more options, visit this group at
> > > http://groups.google.com/group/propel-development
> >  --  
Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Markus Staab 12/28/12 11:03 AM
+1, any progress on this topic for propel2?
Re: [propel-dev] Ability to return extended PropelObjectCollection from query? Lee Leathers 12/30/12 9:19 AM
Hey,  

I have a pull request in for a code review to see if people like how it's implement. After the thumbs up, I'll write the tests.  

--  
Lee Leathers
about.me/leeleathers
706-340-7424


On Friday, December 28, 2012 at 11:03 AM, Markus Staab wrote:

> +1, any progress on this topic for propel2?
>  
> On Friday, October 19, 2012 8:50:53 PM UTC+2, Lee Leathers wrote:
> > 2.0 it is.  
> >  
> >  
> >  
> > --  
> >  
> > Lee Leathers
> >  
> > about.me/leeleathers (http://about.me/leeleathers)
> > > > > > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com) (mailto:propel-development%2Bunsubscribe@googlegroups.com (mailto:propel-development%252Bunsubscribe@googlegroups.com (mailto:252Buns...@googlegroups.com)))
> >  
> > > > > > > > > For more options, visit this group at
> >  
> > > > > > > > > http://groups.google.com/group/propel-development
> >  
> >  
> >  
> > > > > > > > --
> >  
> > > > > > > > Google+: https://plus.google.com/111881868112036203454
> >  
> >  
> > > > > > > > --
> >  
> > > > > > > > You received this message because you are subscribed to the Google
> >  
> > > > > > > > Groups "Propel Development" group.
> >  
> > > > > > > > To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com) (mailto:propel-de...@googlegroups.com)
> >  
> > > > > > > > To unsubscribe from this group, send email to
> >  
> > > > > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com) (mailto:propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com (mailto:2Bunsu...@googlegroups.com)))
> >  
> > > > > > > > For more options, visit this group at
> >  
> > > > > > > > http://groups.google.com/group/propel-development
> >  
> >  
> >  
> > > > > > >  --
> >  
> > > > > > >  You received this message because you are subscribed to the Google
> >  
> > > > > > >  Groups "Propel Development" group.
> >  
> > > > > > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> >  
> > > > > > >  To unsubscribe from this group, send email to
> >  
> > > > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com (mailto:2Bunsu...@googlegroups.com))
> >  
> > > > > > >  For more options, visit this group at
> >  
> > > > > > > http://groups.google.com/group/propel-development
> >  
> >  
> >  
> >  
> > > > > > --  
> >  
> > > > > > Google+: https://plus.google.com/111881868112036203454
> >  
> >  
> >  
> > > > > >  --  
> >  
> > > > > >  You received this message because you are subscribed to the Google
> >  
> > > > > >  Groups "Propel Development" group.
> >  
> > > > > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> >  
> > > > > >  To unsubscribe from this group, send email to
> >  
> > > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development+unsubscribe@googlegroups.com)
> >  
> > > > > >  For more options, visit this group at
> >  
> > > > > > http://groups.google.com/group/propel-development
> >  
> > > > >  --  
> >  
> > > > >  You received this message because you are subscribed to the Google
> >  
> > > > >  Groups "Propel Development" group.
> >  
> > > > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> >  
> > > > >  To unsubscribe from this group, send email to
> >  
> > > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development%2Bunsubscribe@googlegroups.com (mailto:2Bunsu...@googlegroups.com))
> >  
> > > > >  For more options, visit this group at
> >  
> > > > > http://groups.google.com/group/propel-development
> >  
> > > >  --  
> >  
> > > >  You received this message because you are subscribed to the Google
> >  
> > > >  Groups "Propel Development" group.
> >  
> > > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> >  
> > > >  To unsubscribe from this group, send email to
> >  
> > > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development+unsubscribe@googlegroups.com)
> >  
> > > >  For more options, visit this group at
> >  
> > > > http://groups.google.com/group/propel-development
> >  
> >  
> > >  --  
> >  
> > >  You received this message because you are subscribed to the Google
> >  
> > >  Groups "Propel Development" group.
> >  
> > >  To post to this group, send email to propel-de...@googlegroups.com (mailto:propel-de...@googlegroups.com)
> >  
> > >  To unsubscribe from this group, send email to
> >  
> > > propel-development+unsubscribe@googlegroups.com (mailto:propel-development+unsubscribe@googlegroups.com)
> >  
> > >  For more options, visit this group at
> >  
> > > http://groups.google.com/group/propel-development
>