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

Using dot in column keys #72

Closed
webysther opened this issue Feb 16, 2017 · 6 comments
Closed

Using dot in column keys #72

webysther opened this issue Feb 16, 2017 · 6 comments

Comments

@webysther
Copy link

webysther commented Feb 16, 2017

SQL fail using 'channel.name' as column. 'channel.name' is a HTML form with format channel[name]:

return [
    'channel.name' => [
        'required',
        'min:3',
        'max:255',
       'unique_with:channels,name,product_id,'.$this->route('channel')
    ],
    'channel.product_id' => 'required',
];
@webysther webysther changed the title Using dot with column on rules fail Using dot in column keys Feb 16, 2017
@felixkiss
Copy link
Owner

@webysther Please help test out #73 and give feedback if possible. It is based on version 3.0.0, so you need to upgrade (Usually only thing necessary is to update the service provider class in your config/app.php, which has been renamed)

@webysther
Copy link
Author

Hi @felixkiss works partially, the problem of SQL is fine, but now search works but dont check all columns, example:

For rule:

unique_with:search_filters,search.name = name, search.user_id = user_id

Return the message:

This combination of search.name, search.user id already exists.

And the SQL executed is by validation:

select count(*) as aggregate from `search_filters` where `name` = 'teste'

My create statment:

CREATE TABLE `search_filters` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `filter` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `deleted_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `created_by` int(10) unsigned DEFAULT NULL,
  `updated_by` int(10) unsigned DEFAULT NULL,
  `deleted_by` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_search_filters` (`user_id`,`name`,`deleted_at`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Rows in table:

# id, user_id, name, filter, created_at, updated_at, deleted_at, created_by, updated_by, deleted_by
'2', '20', 'teste', 'action-search=&period=&product_id=&requester_auto_complete=&requester_id=&search_term=&status=pending', '2017-02-22 17:55:10', '2017-02-22 17:55:19', '2017-02-22 17:55:19', '20', '20', NULL
'3', '20', 'teste', 'action-search=&period=&product_id=&requester_auto_complete=&requester_id=&search_term=&status=pending', '2017-02-22 18:05:41', '2017-02-22 18:05:41', '0000-00-00 00:00:00', '20', '20', NULL

@webysther
Copy link
Author

@felixkiss maybe is related to laravel/framework#1820
On my case check null not work, i need set value '0000-00-00 00:00:00'

@felixkiss
Copy link
Owner

I just tried it myself. I had the exact same problem as you until I noticed that I wasn't using the dot-validation branch. What does your composer.json look like? Should be something like

{
    "require": {
        "felixkiss/uniquewith-validator": "dev-dot-validation"
    }
}

@felixkiss
Copy link
Owner

As for the deleted_at problem: Just set the value to ignore (in your case 0000-00-00 00:00:00) in the validator data array like so:

$data = [
    'search' => [
        'name' => 'foo',
        'user_id' => 2,
    ],
    'deleted_at' => '0000-00-00 00:00:00',
];

$rules = [
    'search.name' => 'required|unique_with:search_filters, search.name = name, search.user_id = user_id, deleted_at',
    'search.user_id' => 'required',
];

$validator = Validator::make($data, $rules);

@webysther
Copy link
Author

Now works! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants