diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index e5f0f7698..3b51f647c 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -741,7 +741,7 @@ func templateDialectSqlOpenTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlPredicateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\xdf\x4f\xe3\x38\x10\x7e\x6e\xff\x8a\x11\xaa\x74\x09\x2a\x2e\x2d\xf0\x70\x27\x71\x12\xea\x82\xd4\xbb\x85\x72\xea\xea\xee\x01\xa1\x95\x49\x26\xad\x77\x8d\x1d\x6c\xb7\x08\x65\xf3\xbf\x9f\xec\xb8\x69\xd2\xa6\xc0\x15\xd0\xbd\xec\x13\x69\x66\x3c\x3f\xbe\xef\x9b\x89\x45\x96\xf5\xf6\xdb\x43\x99\x3e\x29\x36\x9d\x19\x18\x1c\xf6\x7f\x3d\x48\x15\x6a\x14\x06\x2e\x68\x84\x77\x52\x7e\x87\x91\x88\x08\x9c\x71\x0e\xce\x49\x83\xb5\xab\x05\xc6\xa4\xfd\x65\xc6\x34\x68\x39\x57\x11\x42\x24\x63\x04\xa6\x81\xb3\x08\x85\xc6\x18\xe6\x22\x46\x05\x66\x86\x70\x96\xd2\x68\x86\x30\x20\x87\x4b\x2b\x24\x72\x2e\xe2\x36\x13\xce\xfe\x79\x34\x3c\xbf\x9a\x9c\x43\xc2\x38\x82\x7f\xa7\xa4\x34\x10\x33\x85\x91\x91\xea\x09\x64\x02\xa6\x92\xcc\x28\x44\xd2\xde\xef\xe5\x79\xbb\x9d\x65\x10\x63\xc2\x04\xc2\x5e\xcc\x28\xc7\xc8\xf4\xf4\x03\xef\xa5\x0a\x63\x16\x51\x83\x3d\x16\xef\xc1\x41\x9e\xb7\x5b\xc9\x5c\x44\x81\x86\x7d\xfd\xc0\xc9\x04\xb9\x0b\x1d\x42\xd6\x6e\xb5\xb2\xec\x00\x58\x02\x1d\x32\xfa\x44\x46\x7a\x62\x14\x13\x53\xc8\x73\x16\x77\xe1\x2b\xfc\x76\x0a\xda\xa8\x48\x8a\x05\x39\x33\x92\x05\x2c\x0e\xad\x3f\x8a\x18\x6c\xd4\x96\x26\xff\xcc\x50\x61\x60\xc3\x9e\xff\x15\x68\x32\x0c\xb2\xac\x88\x35\x94\x42\x1b\x2a\x0c\xe4\x79\xd8\x05\x16\x87\x61\xbb\x95\xb7\x2b\xa7\x5f\x53\x7d\x4f\xa6\xda\x77\x60\x4f\x76\x64\x6a\x4b\xea\x90\x49\x24\x53\x24\xe3\xb4\x62\xa2\x6a\x5a\xb5\x9d\xa9\x69\xc5\xa8\x8d\x54\x74\x8a\x55\x87\x89\x7f\xf5\x4a\x78\x64\x4a\xfe\xa6\x8a\xd1\x98\x45\x45\xeb\xad\x5e\xcf\x1a\x84\x34\x40\xd5\x74\x7e\x8f\xc2\x68\x78\x44\x85\x90\x2a\xb9\x60\x31\xc6\x5d\xa0\x69\x6a\x9b\xb5\xa4\x5e\x9c\x7d\x9e\x9c\x43\xe4\x41\xd1\x5d\x1f\x41\x33\x11\x21\x3c\x22\x44\x54\xfc\x62\xec\x01\xfe\x04\x7b\xa3\x2b\x08\xc2\x3d\x02\x4e\x64\x8f\x8c\x73\xb8\xa7\xdf\xb1\x90\x41\x09\x0f\x24\x94\xeb\x27\x62\x03\xb1\x04\x38\x0a\x07\xbd\x85\x21\xcf\x43\x38\x3d\x85\x43\xd7\x40\x9d\xa4\x0b\xca\x35\x06\x96\x8b\x56\xab\xa5\xd0\xcc\x95\xb0\x8f\xae\xa1\x85\x85\xc7\x26\x0a\x6e\x6e\x99\x30\xa8\x12\x1a\x61\x96\x77\xd7\x63\xbb\xc3\x89\x54\xc0\xec\x01\x45\xc5\x14\x61\xe1\x73\x65\x59\x93\x98\x16\x37\xec\xd6\xca\x69\x4d\x4d\xab\x98\x37\xec\x36\xcc\x32\x40\xae\xd1\xbb\xc3\x29\xd4\xcc\xd6\xba\x54\x9d\x2b\xd7\x29\xc9\xfa\x37\xe4\x73\x98\x34\x0a\xb8\xd2\xc6\x32\x46\x93\x96\xb3\x0c\x22\xca\x79\x29\x1c\x32\x4e\x87\x76\xc8\xad\x00\xf3\xfc\x19\x9d\xfb\xfe\xeb\x6a\x59\x10\x42\x56\xdd\xb1\xb8\xec\x65\x87\x99\x48\x18\xf2\xb8\x3a\x12\x49\x55\xd4\x17\xd6\xfa\x92\xa4\xb7\x0c\x6d\xb2\xd6\xca\x62\xd7\xea\xd6\x87\x76\x5b\x85\x3f\x27\xfa\x83\x27\xfa\xad\xf2\xae\x2b\xa2\x90\xb6\x45\xc7\x42\x77\xc5\xb8\x47\xae\x0b\x8b\x46\xd5\x7b\xd1\xbb\xfc\x6f\x51\x3c\xc6\x53\xec\xcd\x68\x4d\x52\x35\xde\xcf\xe3\xd7\x93\x8e\xe4\x72\x70\x09\x9e\x6f\xd3\x77\xfb\x81\x7c\xa1\x77\x1c\x03\x87\xe0\xdd\x9c\x71\xfb\xed\xb6\xef\x1f\x38\xf9\x54\x54\x14\xe8\xf2\xa9\x00\x7a\x09\x66\xc1\xc6\x03\x27\x23\x51\x3c\xb7\x4c\x7f\xdb\x6e\x28\xec\x3e\x81\x2f\xcf\x79\x22\xb9\xfe\xb3\xe2\x79\xe3\xd1\x44\x32\xd2\x23\xb1\x40\xe5\xb6\x46\x7f\xb5\x40\x0e\x4b\x34\x6f\x43\x52\x44\x6d\x5d\x28\x79\x1f\x2c\x63\x17\xfd\x14\xa1\xdd\x73\xb5\x0e\x5f\x48\xf1\x27\x5c\x5b\xa4\x52\x15\x10\x8d\x21\xa0\x22\xb6\xcf\xe3\xc1\xb8\x56\x4a\xe8\xd8\xec\xed\x83\x75\xfa\xf1\x03\x02\xeb\xf0\xc8\xcc\x0c\x98\xaf\xd5\xf2\x15\x82\xbb\xa0\x34\x63\x5c\x55\xe2\x95\x34\x57\x73\xce\x83\x12\x36\x24\x43\xc9\xe7\xf7\xa2\x56\x72\xad\x4c\x9f\x7f\x3c\xb8\xac\xe7\xa7\x5a\xcb\xe8\xe5\xec\xff\x0f\xc3\x9b\x4d\xed\xc0\xdc\xf2\xc8\x26\x7c\x5b\x91\x6b\x24\xdb\xaf\x84\x1d\xe7\xd0\x82\xfd\xfe\xb3\x68\x3b\x70\xf7\x89\x7e\xb1\x2e\x3a\xdf\xec\x8f\x43\xf7\xe3\xa0\x61\x1e\x0a\xff\xa5\x87\x75\x2f\x8f\xda\x8e\x0e\x8a\xa8\xaf\x24\xbb\x41\x26\x66\x60\x5f\xd5\x79\xf1\x37\x1c\x57\x8e\x40\xe8\x14\xaf\x1d\x57\x4f\xa9\x27\x6c\x99\xb9\xe8\x08\x89\xaf\x78\x9d\xcc\x32\x94\x93\x74\x79\xc6\xb9\xad\x6c\xab\x46\x8a\x9a\x8e\x36\x6b\xda\xa2\x15\xe7\x7e\x5c\x75\xf7\x72\x34\x47\xe5\xa0\x6d\x6c\x9d\xce\x37\xb7\x53\xbc\xce\x9c\x30\xcd\x91\xff\xf5\x87\x64\x22\x30\x03\xff\x6b\x2c\x9e\x0f\xc4\x5c\xa0\x2e\x98\x41\xe9\xe4\x20\x5a\x9b\x98\xa2\xcc\x93\x86\x32\x43\x52\xa4\x1f\x94\x97\xcd\xaf\x5d\x48\x57\xf7\x4d\x2b\x4b\xed\xbf\x86\x69\x60\x4e\xc2\xf2\x16\x6b\x8e\xdd\xd1\x65\xbb\x27\x1b\x2b\x67\x24\x82\xed\x23\x0c\xe6\x38\xfc\xf8\xa5\xf8\x5e\xb2\xac\xad\x98\x26\x80\x49\xc3\x76\xf9\x78\x15\x37\x6b\xb2\x51\xd6\xaf\xa3\x77\xb0\xa2\x77\x1b\x93\x4d\xdb\xcf\xea\x6f\xf7\x6f\xc7\x87\x90\xd4\xf0\x1d\xf8\x0f\x1f\x80\xf7\x02\xab\x41\xf6\x15\xa0\x76\xfb\x3c\x50\xf1\xf2\xff\x1a\xb4\xc7\x6a\xc8\xa5\xc0\x20\x24\x13\x34\xd7\x81\x60\xdc\xa6\x6e\xee\xcb\xc5\xf6\xcd\xa5\x81\xee\x5b\xcf\xda\x6d\xb6\x4f\xae\x83\x1d\x2e\x95\x52\xbd\xb9\x58\xf6\x6c\xb1\x2c\x01\x06\xbf\xaf\x6e\xec\x7d\x32\x56\xc1\x8a\x99\xf7\xec\x45\x48\xf3\x62\x33\x69\xa0\xed\x65\x61\x33\xfc\xbf\x01\x00\x00\xff\xff\xde\x4a\xc1\x6a\x07\x13\x00\x00") +var _templateDialectSqlPredicateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x57\xc1\x6e\x1b\x37\x10\x3d\x4b\x5f\x31\x30\x04\x94\x6b\x28\x94\xa5\x24\x87\x16\x70\x01\x43\xb1\x51\xb5\x89\x94\x56\x46\x7b\x30\x8c\x80\x5e\xce\x4a\x6c\x68\x72\x43\x52\x32\x84\xcd\xfe\x7b\x41\x2e\x25\xad\xe4\x55\xec\xda\x6e\x4e\xbd\x69\x39\x8f\xc3\x99\xf7\xde\xd0\x74\x51\xf4\x8e\xdb\x43\x9d\xaf\x8c\x98\xcd\x1d\x0c\x4e\xfa\x3f\xbe\xca\x0d\x5a\x54\x0e\x2e\x58\x8a\x37\x5a\x7f\x86\x91\x4a\x29\x9c\x49\x09\x01\x64\xc1\xc7\xcd\x12\x39\x6d\x5f\xce\x85\x05\xab\x17\x26\x45\x48\x35\x47\x10\x16\xa4\x48\x51\x59\xe4\xb0\x50\x1c\x0d\xb8\x39\xc2\x59\xce\xd2\x39\xc2\x80\x9e\xac\xa3\x90\xe9\x85\xe2\x6d\xa1\x42\xfc\xfd\x68\x78\x3e\x9e\x9e\x43\x26\x24\x42\x5c\x33\x5a\x3b\xe0\xc2\x60\xea\xb4\x59\x81\xce\xc0\xd5\x0e\x73\x06\x91\xb6\x8f\x7b\x65\xd9\x6e\x17\x05\x70\xcc\x84\x42\x38\xe2\x82\x49\x4c\x5d\xcf\x7e\x91\xbd\xdc\x20\x17\x29\x73\xd8\x13\xfc\x08\x5e\x95\x65\xbb\x95\x2d\x54\x4a\x2c\x1c\xdb\x2f\x92\x4e\x51\x86\xd4\x09\x14\xed\x56\xab\x28\x5e\x81\xc8\xa0\x43\x47\xef\xe8\xc8\x4e\x9d\x11\x6a\x06\x65\x29\x78\x17\x3e\xc1\x4f\xa7\x60\x9d\x49\xb5\x5a\xd2\x33\xa7\x05\x11\x3c\xf1\x78\x54\x1c\x7c\xd6\x96\xa5\x7f\xcd\xd1\x20\xf1\x69\xcf\x7f\x27\x96\x0e\x49\x51\x54\xb9\x86\x5a\x59\xc7\x94\x83\xb2\x4c\xba\x20\x78\x92\xb4\x5b\x65\xbb\xb6\xfb\x31\xd5\xf7\x74\x6e\x63\x07\x7e\x67\x47\xe7\xbe\xa4\x0e\x9d\xa6\x3a\x47\x3a\xc9\x6b\x21\x66\x66\xf5\xd8\x99\x99\xd5\x82\xd6\x69\xc3\x66\x58\x07\x4c\xe3\xd2\x23\xe9\xd1\x39\xfd\x93\x19\xc1\xb8\x48\xab\xd6\x5b\xbd\x9e\x0f\x28\xed\x80\x99\xd9\xe2\x16\x95\xb3\x70\x87\x06\x21\x37\x7a\x29\x38\xf2\x2e\xb0\x3c\xf7\xcd\x7a\x51\x2f\xce\xde\x4f\xcf\x21\x8d\xa4\xd8\x6e\xcc\x60\x85\x4a\x11\xee\x10\x52\xa6\x7e\x70\x7e\x83\x5c\xc1\xd1\x68\x0c\x24\x39\xa2\x10\x4c\x76\x27\xa4\x84\x5b\xf6\x19\x2b\x1b\x6c\xe8\x81\x8c\x49\xbb\xa2\x3e\x91\xc8\x40\xa2\x0a\xd4\x7b\x1a\xca\x32\x81\xd3\x53\x38\x09\x0d\xec\x8a\x74\xc1\xa4\x45\xe2\xb5\x68\xb5\x5a\x06\xdd\xc2\x28\xff\x33\x34\xb4\xf4\xf4\xf8\x83\xc8\xd5\xb5\x50\x0e\x4d\xc6\x52\x2c\xca\xee\x7e\xee\xb0\x39\xd3\x06\x84\xdf\x60\x98\x9a\x21\x2c\xe3\x59\x45\xd1\x64\xa6\xe5\x95\xb8\xf6\x76\xda\x73\xd3\x36\xe7\x95\xb8\x4e\x8a\x02\x50\x5a\x8c\x70\x38\x85\x9d\xb0\x8f\xae\x5d\x17\xca\x0d\x4e\xf2\xf8\x86\xf3\x02\x27\x8d\x06\xae\xb5\xb1\xce\xd1\xe4\xe5\xa2\x80\x94\x49\xb9\x31\x0e\x9d\xe4\x43\x3f\xe4\xde\x80\x65\xf9\x0d\x9f\xc7\xfe\x77\xdd\xb2\xa4\x94\x6e\xbb\x13\x7c\xd3\xcb\x13\x66\x22\x13\x28\x79\x7d\x24\xb2\xba\xa9\x2f\x7c\xf4\x21\x4b\x1f\x18\xda\x6c\xaf\x95\xe5\x53\xab\xdb\x1f\xda\x43\x15\xfe\x3f\xd1\xff\xf1\x44\x3f\xd7\xde\xbb\x8e\xa8\xac\xed\xd9\xf1\xd4\x8d\x85\x8c\xcc\x75\x61\xd9\xe8\xfa\x68\xfa\x70\xfe\x73\x1c\x8f\x7c\x86\xbd\x39\xdb\xb1\xd4\x8e\xee\xe7\xfc\x61\xd1\xad\xc3\x60\x34\x1f\x19\xe3\xdd\xd4\x61\x4e\x3c\x4d\x81\x41\xa3\x6f\xc9\x25\xbb\x91\x18\xe6\xf7\xfe\x54\xaf\x81\x97\x3a\xd0\x82\x34\x80\x6b\x90\x07\xf6\xf9\x02\xd7\xbc\x77\x90\xfe\x81\x92\x5e\xae\x72\xdc\x6c\x44\x3a\xb2\x23\xb5\x44\x63\xeb\x6b\xf7\x0e\x89\x17\x6c\xe5\x5e\xa4\x1f\x06\x1f\xaa\xae\xe3\xbd\xdb\x41\xfa\xf1\xb7\x1a\x9e\x52\xba\xd9\x11\xae\x9e\x3d\xf0\x50\xcb\xc5\xad\xaa\x6d\xd8\xa2\x15\x5f\x83\x43\x13\xde\x5b\xbe\xfc\x5f\x98\x1d\xa3\x98\xcd\x6f\xb4\xb1\xc4\x76\xc1\x93\xfa\x74\x3d\xef\x84\x9b\x3f\x4b\xd3\x5d\x2a\x62\x03\xbe\xb7\xf0\x77\xa9\x5f\xd9\xae\xf3\xb7\xff\x38\x09\x1f\x6b\x78\x9d\xed\x0a\xbf\x46\x78\xf8\x66\x6b\x8d\x86\x9b\x85\x90\xfe\x49\x17\x1d\xf4\xae\x6a\x8c\xd8\xcd\xaf\x6a\xfe\x5c\x3f\x20\x2a\xe9\x48\xb5\x34\xf0\x4b\x71\x7f\x0c\xd4\x85\x54\x08\x9d\x6a\x39\x68\xbe\xca\xa3\xf0\xfb\x6a\xc5\x8a\xf7\x4d\x71\x40\xe1\x00\x6b\xd4\x33\xd4\xf4\xfa\x7e\x4d\xcd\x9e\xab\xe0\x6f\xea\xf0\x4a\x03\xe2\x5e\xc7\x4b\x62\xcf\x75\x57\x15\x89\x65\x79\x9d\x24\x95\xff\xc2\x78\xb9\xd7\xf1\xeb\x57\x2d\x14\x71\x83\xf8\x35\x51\xdf\x4e\x24\x42\xa2\x2e\xb8\xc1\x06\x14\x28\xda\x9b\xb4\xaa\xcc\xb7\x0d\x65\x26\xd5\x74\xbb\xc1\xe6\xd1\xf2\xa9\x0b\xf9\xf6\xdd\xe2\x6d\x69\xe3\xad\x9a\x13\xf7\x36\xd9\xbc\x86\xdc\x9b\xb0\x75\xdd\x6e\x15\xa9\x5f\xa2\x23\x45\x5c\xff\xe0\x43\xc0\xbd\x49\x92\xbd\x57\x8a\x36\x95\x57\x27\x40\x98\xe2\xfe\xf7\x64\x30\xd9\xf1\x63\x12\x8c\xd7\x3b\x06\x0f\xfa\xfa\x15\x88\x07\xf8\x39\x01\x11\x0d\xeb\x87\x27\x81\xf0\xfa\x7f\x41\x5b\xc6\x26\x0f\x13\x5c\xb1\xf8\xbd\x5d\xdc\xec\xc9\x46\x5b\x3f\x4e\xde\xc1\x56\xde\x43\x4a\x36\xdc\x8b\xc1\x7f\xbb\x6a\x46\x99\x26\x83\x0f\xbb\x32\x31\x6b\x75\xfa\x3d\x44\xba\x5f\x64\x93\x44\x07\x86\xfa\xc5\xc8\x6a\xb0\x7d\x8d\xa8\xf8\xf2\xf8\x97\x7f\x1e\x98\x7a\xf8\x7f\x56\x1b\xb9\x1a\x4a\xad\x90\x24\x74\x8a\xee\x23\x51\x42\xfa\xa3\x9b\xfb\x0a\xb9\x63\x73\x39\xb1\x7d\x8f\xdc\x79\x15\xf5\xe9\x47\xf2\x84\xc7\x89\x36\xcf\x2e\x56\x7c\xb3\x58\x91\x81\x80\x9f\xb7\x2f\xbf\x3e\x9d\x18\xb2\x55\xe6\x25\x7b\x51\xda\x3d\xd8\x4c\x4e\x2c\x1d\x6b\x77\x3f\xfd\x3f\x01\x00\x00\xff\xff\xe8\xcb\x1b\xa4\x4f\x11\x00\x00") func templateDialectSqlPredicateTmplBytes() ([]byte, error) { return bindataRead( @@ -756,7 +756,7 @@ func templateDialectSqlPredicateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/predicate.tmpl", size: 4871, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/dialect/sql/predicate.tmpl", size: 4431, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/dialect/sql/predicate.tmpl b/entc/gen/template/dialect/sql/predicate.tmpl index b543a30f9..861085b6f 100644 --- a/entc/gen/template/dialect/sql/predicate.tmpl +++ b/entc/gen/template/dialect/sql/predicate.tmpl @@ -62,31 +62,18 @@ in the LICENSE file in the root directory of this source tree. {{ define "dialect/sql/predicate/edge/has" -}} {{- $e := $.Scope.Edge -}} func(s *sql.Selector) { - {{- if $e.M2M }} - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C({{ $.ID.Constant }}), - builder.Select({{ $e.PKConstant }}[{{ if $e.IsInverse }}1{{ else }}0{{ end }}]). - From(builder.Table({{ $e.TableConstant }})), - ), - ) - {{- else if or $e.M2O (and $e.O2O $e.IsInverse) }}{{/* M2O || (O2O with inverse edge) */}} - t1 := s.Table() - s.Where(sql.NotNull(t1.C({{ $e.ColumnConstant }}))) - {{- else }}{{/* O2M || (O2O with assoc edge) */}} - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C({{ $.ID.Constant }}), - builder.Select({{ $e.ColumnConstant }}). - From(builder.Table({{ $e.TableConstant }})). - Where(sql.NotNull({{ $e.ColumnConstant }})), - ), - ) - {{- end }} + step := sql.NewStep( + sql.From(Table, {{ $.ID.Constant }}), + sql.To({{ $e.TableConstant }}, {{ $.ID.Constant }}), + sql.Edge(sql.{{ $e.Rel.Type }}, {{ $e.IsInverse }}, {{ $e.TableConstant }}, + {{- if $e.M2M -}} + {{ $e.PKConstant }}... + {{- else -}} + {{ $e.ColumnConstant }} + {{- end -}} + ), + ) + sql.HasNeighbors(s, step) } {{- end }} diff --git a/entc/integration/customid/ent/group/where.go b/entc/integration/customid/ent/group/where.go index 670416242..d830f4454 100644 --- a/entc/integration/customid/ent/group/where.go +++ b/entc/integration/customid/ent/group/where.go @@ -116,15 +116,12 @@ func IDLTE(id int) predicate.Group { func HasUsers() predicate.Group { return predicate.Group( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(UsersPrimaryKey[0]). - From(builder.Table(UsersTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(UsersTable, FieldID), + sql.Edge(sql.M2M, false, UsersTable, UsersPrimaryKey...), ) + sql.HasNeighbors(s, step) }, ) } diff --git a/entc/integration/customid/ent/user/where.go b/entc/integration/customid/ent/user/where.go index 2cc5e283b..09b043300 100644 --- a/entc/integration/customid/ent/user/where.go +++ b/entc/integration/customid/ent/user/where.go @@ -116,15 +116,12 @@ func IDLTE(id int) predicate.User { func HasGroups() predicate.User { return predicate.User( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(GroupsPrimaryKey[1]). - From(builder.Table(GroupsTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(GroupsTable, FieldID), + sql.Edge(sql.M2M, true, GroupsTable, GroupsPrimaryKey...), ) + sql.HasNeighbors(s, step) }, ) } diff --git a/entc/integration/ent/card/where.go b/entc/integration/ent/card/where.go index 38b1c4ba1..b9ddad64d 100644 --- a/entc/integration/ent/card/where.go +++ b/entc/integration/ent/card/where.go @@ -772,8 +772,12 @@ func NameNotNil() predicate.Card { func HasOwner() predicate.Card { return predicate.CardPerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(OwnerColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(OwnerTable, FieldID), + sql.Edge(sql.O2O, true, OwnerTable, OwnerColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(OwnerInverseLabel).InV() diff --git a/entc/integration/ent/file/where.go b/entc/integration/ent/file/where.go index 47192ed8d..05d0a6d6c 100644 --- a/entc/integration/ent/file/where.go +++ b/entc/integration/ent/file/where.go @@ -831,8 +831,12 @@ func GroupNotNil() predicate.File { func HasOwner() predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(OwnerColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(OwnerTable, FieldID), + sql.Edge(sql.M2O, true, OwnerTable, OwnerColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(OwnerInverseLabel).InV() @@ -866,8 +870,12 @@ func HasOwnerWith(preds ...predicate.User) predicate.File { func HasType() predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(TypeColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(TypeTable, FieldID), + sql.Edge(sql.M2O, true, TypeTable, TypeColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(TypeInverseLabel).InV() diff --git a/entc/integration/ent/filetype/where.go b/entc/integration/ent/filetype/where.go index 8dccc84e7..133bb0eef 100644 --- a/entc/integration/ent/filetype/where.go +++ b/entc/integration/ent/filetype/where.go @@ -327,16 +327,12 @@ func NameHasSuffix(v string) predicate.FileType { func HasFiles() predicate.FileType { return predicate.FileTypePerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FilesColumn). - From(builder.Table(FilesTable)). - Where(sql.NotNull(FilesColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FilesTable, FieldID), + sql.Edge(sql.O2M, false, FilesTable, FilesColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(FilesLabel).OutV() diff --git a/entc/integration/ent/group/where.go b/entc/integration/ent/group/where.go index 53250f17b..8f95c0dd2 100644 --- a/entc/integration/ent/group/where.go +++ b/entc/integration/ent/group/where.go @@ -832,16 +832,12 @@ func NameHasSuffix(v string) predicate.Group { func HasFiles() predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FilesColumn). - From(builder.Table(FilesTable)). - Where(sql.NotNull(FilesColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FilesTable, FieldID), + sql.Edge(sql.O2M, false, FilesTable, FilesColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(FilesLabel).OutV() @@ -875,16 +871,12 @@ func HasFilesWith(preds ...predicate.File) predicate.Group { func HasBlocked() predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(BlockedColumn). - From(builder.Table(BlockedTable)). - Where(sql.NotNull(BlockedColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(BlockedTable, FieldID), + sql.Edge(sql.O2M, false, BlockedTable, BlockedColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(BlockedLabel).OutV() @@ -918,15 +910,12 @@ func HasBlockedWith(preds ...predicate.User) predicate.Group { func HasUsers() predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(UsersPrimaryKey[1]). - From(builder.Table(UsersTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(UsersTable, FieldID), + sql.Edge(sql.M2M, true, UsersTable, UsersPrimaryKey...), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(UsersInverseLabel).InV() @@ -967,8 +956,12 @@ func HasUsersWith(preds ...predicate.User) predicate.Group { func HasInfo() predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(InfoColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(InfoTable, FieldID), + sql.Edge(sql.M2O, false, InfoTable, InfoColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(InfoLabel).OutV() diff --git a/entc/integration/ent/groupinfo/where.go b/entc/integration/ent/groupinfo/where.go index 2ee2de5a0..f5b4a10bc 100644 --- a/entc/integration/ent/groupinfo/where.go +++ b/entc/integration/ent/groupinfo/where.go @@ -455,16 +455,12 @@ func MaxUsersLTE(v int) predicate.GroupInfo { func HasGroups() predicate.GroupInfo { return predicate.GroupInfoPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(GroupsColumn). - From(builder.Table(GroupsTable)). - Where(sql.NotNull(GroupsColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(GroupsTable, FieldID), + sql.Edge(sql.O2M, true, GroupsTable, GroupsColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(GroupsInverseLabel).InV() diff --git a/entc/integration/ent/node/where.go b/entc/integration/ent/node/where.go index 22255f54f..5e8ff2bf2 100644 --- a/entc/integration/ent/node/where.go +++ b/entc/integration/ent/node/where.go @@ -315,8 +315,12 @@ func ValueNotNil() predicate.Node { func HasPrev() predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(PrevColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(PrevTable, FieldID), + sql.Edge(sql.O2O, true, PrevTable, PrevColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(PrevInverseLabel).InV() @@ -350,16 +354,12 @@ func HasPrevWith(preds ...predicate.Node) predicate.Node { func HasNext() predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(NextColumn). - From(builder.Table(NextTable)). - Where(sql.NotNull(NextColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(NextTable, FieldID), + sql.Edge(sql.O2O, false, NextTable, NextColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(NextLabel).OutV() diff --git a/entc/integration/ent/pet/where.go b/entc/integration/ent/pet/where.go index da6e00320..7c193817f 100644 --- a/entc/integration/ent/pet/where.go +++ b/entc/integration/ent/pet/where.go @@ -327,8 +327,12 @@ func NameHasSuffix(v string) predicate.Pet { func HasTeam() predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(TeamColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(TeamTable, FieldID), + sql.Edge(sql.O2O, true, TeamTable, TeamColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(TeamInverseLabel).InV() @@ -362,8 +366,12 @@ func HasTeamWith(preds ...predicate.User) predicate.Pet { func HasOwner() predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(OwnerColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(OwnerTable, FieldID), + sql.Edge(sql.M2O, true, OwnerTable, OwnerColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(OwnerInverseLabel).InV() diff --git a/entc/integration/ent/user/where.go b/entc/integration/ent/user/where.go index 9de0cc23d..ee19eeace 100644 --- a/entc/integration/ent/user/where.go +++ b/entc/integration/ent/user/where.go @@ -1183,16 +1183,12 @@ func PasswordNotNil() predicate.User { func HasCard() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(CardColumn). - From(builder.Table(CardTable)). - Where(sql.NotNull(CardColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(CardTable, FieldID), + sql.Edge(sql.O2O, false, CardTable, CardColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(CardLabel).OutV() @@ -1226,16 +1222,12 @@ func HasCardWith(preds ...predicate.Card) predicate.User { func HasPets() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(PetsColumn). - From(builder.Table(PetsTable)). - Where(sql.NotNull(PetsColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(PetsTable, FieldID), + sql.Edge(sql.O2M, false, PetsTable, PetsColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(PetsLabel).OutV() @@ -1269,16 +1261,12 @@ func HasPetsWith(preds ...predicate.Pet) predicate.User { func HasFiles() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FilesColumn). - From(builder.Table(FilesTable)). - Where(sql.NotNull(FilesColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FilesTable, FieldID), + sql.Edge(sql.O2M, false, FilesTable, FilesColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(FilesLabel).OutV() @@ -1312,15 +1300,12 @@ func HasFilesWith(preds ...predicate.File) predicate.User { func HasGroups() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(GroupsPrimaryKey[0]). - From(builder.Table(GroupsTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(GroupsTable, FieldID), + sql.Edge(sql.M2M, false, GroupsTable, GroupsPrimaryKey...), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(GroupsLabel).OutV() @@ -1361,15 +1346,12 @@ func HasGroupsWith(preds ...predicate.Group) predicate.User { func HasFriends() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FriendsPrimaryKey[0]). - From(builder.Table(FriendsTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FriendsTable, FieldID), + sql.Edge(sql.M2M, false, FriendsTable, FriendsPrimaryKey...), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.Both(FriendsLabel) @@ -1416,15 +1398,12 @@ func HasFriendsWith(preds ...predicate.User) predicate.User { func HasFollowers() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FollowersPrimaryKey[1]). - From(builder.Table(FollowersTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FollowersTable, FieldID), + sql.Edge(sql.M2M, true, FollowersTable, FollowersPrimaryKey...), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(FollowersInverseLabel).InV() @@ -1465,15 +1444,12 @@ func HasFollowersWith(preds ...predicate.User) predicate.User { func HasFollowing() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FollowingPrimaryKey[0]). - From(builder.Table(FollowingTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FollowingTable, FieldID), + sql.Edge(sql.M2M, false, FollowingTable, FollowingPrimaryKey...), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(FollowingLabel).OutV() @@ -1514,16 +1490,12 @@ func HasFollowingWith(preds ...predicate.User) predicate.User { func HasTeam() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(TeamColumn). - From(builder.Table(TeamTable)). - Where(sql.NotNull(TeamColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(TeamTable, FieldID), + sql.Edge(sql.O2O, false, TeamTable, TeamColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(TeamLabel).OutV() @@ -1557,16 +1529,12 @@ func HasTeamWith(preds ...predicate.Pet) predicate.User { func HasSpouse() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(SpouseColumn). - From(builder.Table(SpouseTable)). - Where(sql.NotNull(SpouseColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(SpouseTable, FieldID), + sql.Edge(sql.O2O, false, SpouseTable, SpouseColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.Both(SpouseLabel) @@ -1606,16 +1574,12 @@ func HasSpouseWith(preds ...predicate.User) predicate.User { func HasChildren() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(ChildrenColumn). - From(builder.Table(ChildrenTable)). - Where(sql.NotNull(ChildrenColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(ChildrenTable, FieldID), + sql.Edge(sql.O2M, true, ChildrenTable, ChildrenColumn), ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.InE(ChildrenInverseLabel).InV() @@ -1649,8 +1613,12 @@ func HasChildrenWith(preds ...predicate.User) predicate.User { func HasParent() predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(ParentColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(ParentTable, FieldID), + sql.Edge(sql.M2O, false, ParentTable, ParentColumn), + ) + sql.HasNeighbors(s, step) }, func(t *dsl.Traversal) { t.OutE(ParentLabel).OutV() diff --git a/entc/integration/idtype/ent/user/where.go b/entc/integration/idtype/ent/user/where.go index 7d770a208..0294e1321 100644 --- a/entc/integration/idtype/ent/user/where.go +++ b/entc/integration/idtype/ent/user/where.go @@ -262,16 +262,12 @@ func NameContainsFold(v string) predicate.User { func HasSpouse() predicate.User { return predicate.User( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(SpouseColumn). - From(builder.Table(SpouseTable)). - Where(sql.NotNull(SpouseColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(SpouseTable, FieldID), + sql.Edge(sql.O2O, false, SpouseTable, SpouseColumn), ) + sql.HasNeighbors(s, step) }, ) } @@ -295,15 +291,12 @@ func HasSpouseWith(preds ...predicate.User) predicate.User { func HasFollowers() predicate.User { return predicate.User( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FollowersPrimaryKey[1]). - From(builder.Table(FollowersTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FollowersTable, FieldID), + sql.Edge(sql.M2M, true, FollowersTable, FollowersPrimaryKey...), ) + sql.HasNeighbors(s, step) }, ) } @@ -334,15 +327,12 @@ func HasFollowersWith(preds ...predicate.User) predicate.User { func HasFollowing() predicate.User { return predicate.User( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FollowingPrimaryKey[0]). - From(builder.Table(FollowingTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FollowingTable, FieldID), + sql.Edge(sql.M2M, false, FollowingTable, FollowingPrimaryKey...), ) + sql.HasNeighbors(s, step) }, ) } diff --git a/entc/integration/template/ent/pet/where.go b/entc/integration/template/ent/pet/where.go index 4a21a9d7c..bea8bbf62 100644 --- a/entc/integration/template/ent/pet/where.go +++ b/entc/integration/template/ent/pet/where.go @@ -338,8 +338,12 @@ func LicensedAtNotNil() predicate.Pet { func HasOwner() predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - t1 := s.Table() - s.Where(sql.NotNull(t1.C(OwnerColumn))) + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(OwnerTable, FieldID), + sql.Edge(sql.M2O, true, OwnerTable, OwnerColumn), + ) + sql.HasNeighbors(s, step) }, ) } diff --git a/entc/integration/template/ent/user/where.go b/entc/integration/template/ent/user/where.go index 1f1504b29..76b2b2e79 100644 --- a/entc/integration/template/ent/user/where.go +++ b/entc/integration/template/ent/user/where.go @@ -262,16 +262,12 @@ func NameContainsFold(v string) predicate.User { func HasPets() predicate.User { return predicate.User( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(PetsColumn). - From(builder.Table(PetsTable)). - Where(sql.NotNull(PetsColumn)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(PetsTable, FieldID), + sql.Edge(sql.O2M, false, PetsTable, PetsColumn), ) + sql.HasNeighbors(s, step) }, ) } @@ -295,15 +291,12 @@ func HasPetsWith(preds ...predicate.Pet) predicate.User { func HasFriends() predicate.User { return predicate.User( func(s *sql.Selector) { - t1 := s.Table() - builder := sql.Dialect(s.Dialect()) - s.Where( - sql.In( - t1.C(FieldID), - builder.Select(FriendsPrimaryKey[0]). - From(builder.Table(FriendsTable)), - ), + step := sql.NewStep( + sql.From(Table, FieldID), + sql.To(FriendsTable, FieldID), + sql.Edge(sql.M2M, false, FriendsTable, FriendsPrimaryKey...), ) + sql.HasNeighbors(s, step) }, ) }