(Harici bir kütüphane olmadan) basit ORM

0 Cevap php

Uzun lafın kısası, ben dahil olduğum bir grup projesi proje için dış kitaplıkları kullanmak için izin verilmez.

Biz bu nedeniyle özel bir çerçeve yazdı, ama biz bir noktada sekteye uğruyor. Biz kolayca, (yine böyle Doktrini, uskur, vb gibi yüksek sesle harici kütüphanelere) ilişkileri ele basit bir ORM gerekir ve nasıl bunu yapmak için.

Biz bir model olsaydı, örneğin ...

class ProductsModel extends ModelLib {
    $has_many = array( 'Images' ); // Would relate to Images, get all images with this product_
    $has_one = array( 'User' ); // Would relate to the User, get 1 user who uploaded this product.

Birisi bunu gerçekleştirmek için bir yolda bize yardımcı olabilir, bu yüzden çağırabilirsiniz:

$products = $productsFinder->findAll( ); // returns all product models
foreach( $products AS $product ) {
    print $product->user->name; // gets the user who uploaded the product by relation
    print_r( $prodoct->images ); // returns models of images related to this product.

This is just an example. We pretty much just want to be able to relate the data easily but we don't know of how to do this (code-wise, or even where we should put such code (ie in the finder or model or?). Can anyone please assist :)

0 Cevap