@@ -1397,6 +1397,98 @@ define(['angular', 'given', 'util'], function(angular, given, util) {
13971397 expect ( IgnoredModel ) . to . be . false ;
13981398 } ) ;
13991399 } ) ;
1400+
1401+ describe ( 'inherit params for custom method that extends relation' ,
1402+ function ( ) {
1403+ var $injector , Person , testData ;
1404+ before ( function ( ) {
1405+ return given . servicesForLoopBackApp (
1406+ {
1407+ models : {
1408+ Person : {
1409+ properties : { name : 'string' } ,
1410+ options : {
1411+ relations : {
1412+ _addresses : {
1413+ model : 'Address' ,
1414+ type : 'embedsMany' ,
1415+ property : 'addresses' ,
1416+ } ,
1417+ } ,
1418+ } ,
1419+ } ,
1420+ Address : {
1421+ properties : { name : 'string' } ,
1422+ } ,
1423+ } ,
1424+ name : 'custom_method' ,
1425+ setupFn : ( function ( app , cb ) {
1426+ /*globals debug:true */
1427+ // eslint-disable-next-line camelcase
1428+ app . models . Person . prototype . __custom___address =
1429+ function ( fk , cb ) { return cb ( null , { name : 'custom' } ) ; } ;
1430+ app . models . Person . remoteMethod ( 'prototype.__custom___address' , {
1431+ accepts : [
1432+ {
1433+ arg : 'fk' ,
1434+ type : 'any' ,
1435+ required : true ,
1436+ http : { source : 'path' } ,
1437+ } ,
1438+ ] ,
1439+ returns : [
1440+ {
1441+ arg : 'data' ,
1442+ type : 'object' ,
1443+ root : true ,
1444+ } ,
1445+ ] ,
1446+ http : {
1447+ path : '/_address/:fk/custom' ,
1448+ verb : 'post' ,
1449+ } ,
1450+ } ) ;
1451+ app . models . Person . create (
1452+ { name : 'Matteo' } ,
1453+ function ( err , person ) {
1454+ if ( err ) return cb ( err ) ;
1455+ debug ( 'Created person' , person ) ;
1456+
1457+ person . _addresses . create ( { name : 'Turin' } ,
1458+ function ( err , address ) {
1459+ if ( err ) return cb ( err ) ;
1460+ debug ( 'Created address' , address ) ;
1461+
1462+ person . _addresses ( true , function ( err , res ) {
1463+ if ( err ) return cb ( err ) ;
1464+ debug ( 'Address of the person' , res ) ;
1465+
1466+ cb ( null , {
1467+ person : person ,
1468+ address : address ,
1469+ } ) ;
1470+ } ) ;
1471+ }
1472+ ) ;
1473+ }
1474+ ) ;
1475+ } ) . toString ( ) ,
1476+ } )
1477+ . then ( function ( createInjector ) {
1478+ $injector = createInjector ( ) ;
1479+ Person = $injector . get ( 'Person' ) ;
1480+ testData = $injector . get ( 'testData' ) ;
1481+ } ) ;
1482+ } ) ;
1483+
1484+ it ( 'create correct endpoint for custom method' , function ( ) {
1485+ var customPerson = Person . prototype$__custom___address (
1486+ { id : testData . person . id , fk : testData . address . id } ) ;
1487+ return customPerson . $promise . then ( function ( ) {
1488+ expect ( customPerson . name ) . to . be . equal ( 'custom' ) ;
1489+ } ) ;
1490+ } ) ;
1491+ } ) ;
14001492 } ) ;
14011493
14021494 function propGetter ( name ) {
0 commit comments