Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure default Post sort order shows newer Posts first #381

Merged
merged 1 commit into from
Oct 5, 2016

Conversation

simensen
Copy link
Contributor

@simensen simensen commented Sep 28, 2016

In at least #223 the topic of sorting on the admin backend was mentioned. This is the first time I've loaded the demo app in quite awhile and wasn't sure it was working because I didn't realize the new post I had added was going to show up at the bottom of the list. It may not be a problem for everyone but the bottom of the list on my laptop was well past the fold.

I appreciate that we do not need to make this admin backend fully completed with pagination and column-by-column sorting and what-not. However, I think it would make sense to have newer posts showing up at the top.

*/
public function findAll()
{
return $this->findBy(array(), array('publishedAt' => 'DESC'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simensen, you should use the short array syntax: [].

@@ -28,6 +28,14 @@
class PostRepository extends EntityRepository
{
/**
* @return Post[]
*/
public function findAll()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should use a bit different method name like findAllOrdered() here instead of findAll() as we change its normal behavior from EntityRepository. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about to call the findBy method instead of the findAll in the controller and don't change the findAll behavior at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine either way and had considered these options. I figured it would be easier to submit a PR and start that discussion if someone objected to overriding findAll. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like findAllInChronologicalReversedOrder() (not sure if there is a better English term for this name).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to call it at least in a few different places - the findAllOrdered() is more preferred than findBy(). Otherwise, I'm fine with findBy().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bocharsky-bw, for now we use the findAll only once in the admin controller.
https://github.com/symfony/symfony-demo/search?utf8=%E2%9C%93&q=findAll

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding the builtin doctrine methods to change their behavior is a bad practice IMO, so you should use a different name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I changed to using findBy in the controller.

@bocharsky-bw
Copy link
Contributor

I think that's the simplest solution 👍

@javiereguiluz
Copy link
Member

@simensen thanks! I like this feature and the solution was very simlpe at the end.

@javiereguiluz javiereguiluz merged commit 87584a6 into symfony:master Oct 5, 2016
javiereguiluz added a commit that referenced this pull request Oct 5, 2016
…simensen)

This PR was merged into the master branch.

Discussion
----------

Ensure default Post sort order shows newer Posts first

In at least #223 the topic of sorting on the **admin backend** was mentioned. This is the first time I've loaded the demo app in quite awhile and wasn't sure it was working because I didn't realize the new post I had added was going to show up at the bottom of the list. It may not be a problem for everyone but the bottom of the list on my laptop was well past the fold.

I appreciate that we do not need to make this **admin backend** fully completed with pagination and column-by-column sorting and what-not. However, I think it would make sense to have newer posts showing up at the top.

Commits
-------

87584a6 Ensure default Post sort order shows newer Posts first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants