Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add the mapping option for the PropelParamConverter, #156

Merged
merged 1 commit into from May 23, 2012

Conversation

Projects
None yet
4 participants
Member

jaugustin commented May 22, 2012

Hi,

This Add the mapping option for the PropelParamConverter:

You can map route parameters directly to model column to be use for filtering.

If you have a route like /my-route/{postUniqueName}/{AuthorId}
Mapping option overwrite any other automatic mapping.

<?php

/**
 * @ParamConverter("post", class="BlogBundle\Model\Post", options={"mapping"={"postUniqueName":"name"}})
 * @ParamConverter("author", class="BlogBundle\Model\Author", options={"mapping"={"AuthorId":"id"}})
 */
public function myAction(Post $post, $author)
{
}

this enhance the pk handling to use the real PK name and not only 'id'

this also fix new sensioFrameworkBundle 2.1 requirement:
ParamConverterInterface::apply() method now must return a Boolean value indicating if a conversion was done

this cover #154

@jaugustin jaugustin Add the mapping option for the PropelParamConverter,
enhance the pk handling to use the real PK name and not only 'id',
fix new sensioFrameworkBundle 2.1 requirement:
ParamConverterInterface::apply() method now must return a Boolean value indicating if a conversion was done
b03f6a5

This pull request passes (merged b03f6a5 into f675e39).

@willdurand willdurand commented on the diff May 23, 2012

Request/ParamConverter/PropelParamConverter.php
public function apply(Request $request, ConfigurationInterface $configuration)
{
$classQuery = $configuration->getClass() . 'Query';
+ $classPeer = $configuration->getClass() . 'Peer';
@willdurand

willdurand May 23, 2012

Owner

is it really necessary?

@jaugustin

jaugustin May 23, 2012

Member

If we want it to work with PK not named "id" yes otherwise no

Owner

willdurand commented May 23, 2012

Ok, seems ok then. I didn't dig more into this "ESI" issue, and I hope it's not a hack ;)

Member

jaugustin commented May 23, 2012

it's not a hack, but there is no real ESI issue.

With this you can handle more case like multiple parameters loaded at the same time, with there pks (that was not possible before)

@willdurand willdurand added a commit that referenced this pull request May 23, 2012

@willdurand willdurand Merge pull request #156 from jaugustin/propel-param-converter-mapping…
…-option

Add the mapping option for the PropelParamConverter,
64a6b02

@willdurand willdurand merged commit 64a6b02 into propelorm:1.1 May 23, 2012

Owner

willdurand commented May 23, 2012

Alright, thanks!

Using filters without resetting the array causes invalid behavior when converting parameters in subrequests in symfony. When master request uses this converter for f.ex. a $city in SomeController::someAction(City $city) with mapping "city": "slug", and agin in a subrequest with a different mapping the filters array has mapping from the master request, which causes to generate invalid queies to find a matching row from the database.

FIX (please review):

$this->filters = array();

at the beginning of the apply function

Member

jaugustin replied Jun 3, 2013

@prgTW thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment