rainlab/blog-plugin

error when using categoryFilter if top level Categories do not have nested values

rwcorbett opened this issue · 1 comments

@bennothommo @LukeTowers @chrisvidal - I am not certain how the nested trees work with the blog categories but I have found something that relates to #525 & #526 but is specific to line 333 in Post.php

$categories = $category->getAllChildrenAndSelf()->lists('id');

if the value of nest_left or nest_right is NULL then an error is thrown when using categoryFilter in the view:

Illegal operator and value combination.
C:\_workspace\wcu_website\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php line 591

I found this in development when inserting records into rainlab_blog_categories and leaving those columns NULL.

You should be able to reproduce this but simply running UPDATE rainlab_blog_categories SET nest_right = NULL, nest_left = NULL WHERE id = 4; for any of the categories (does not need to be id 4)

When the nest values are set to 0 no errors are thrown but no posts are returned from the function.

I understand that the average user would not be creating new categories this way, but perhaps the schema creation in categories_add_nested_fields.php should not allow those fields to be NULL?

Here is how I am using it in my view for reference:

title = "Sections"
url = "/blog/:slug/:page?"
layout = "default"
meta_title = "----"
meta_description = "----"
is_hidden = 0

[blogPosts]
pageNumber = "{{ :page }}"
categoryFilter = "{{ :slug }}"
postsPerPage = 9
noPostsMessage = "No posts found!"
sortOrder = "published_at desc"
categoryPage = "blog/sections"
postPage = "blog/story"

@rwcorbett thanks for letting us know. I'm not sure of the rationale for why the columns were set to nullable in the first place, but as you indicated, there's no real way through the CMS that these fields would be null, so it's not really worth changing it at this point.