php - SilverStripe : How to get all records using get() -


a simple question. in code

a customer has many partners. if want customer details , customer have how many partners. trying is,

$customer = customer::get(); return partners::get()->filter('customerid', $customer->id); 

unfortunately above code not working me, there easy way get.?

@mifas you're still getting error because $customer = customer::get() still returning datalist rather single customer object, @zauberfisch described. before call relationship method need sure you're calling on individual customer.

$customer = customer::get()->first(); // or, if you're looking specific customer $customer = customer::get()->filter('id', <custid>)->first(); // if you're looking id only, there shortcut still returns 1 dataobject only: $customer = customer::get()->byid( <custid> ); 

in case, either of following lines work (but relationship 'magic' method @zauberfisch pointed out preferred method)

$partners = $customer->partners(); // or $partners = partner::get()->filter('customerid', $customer->id); 

Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -