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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -