GithubHelp home page GithubHelp logo

creatoro / jelly Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonathangeiger/kohana-jelly

72.0 72.0 13.0 1.34 MB

A flexible ORM for Kohana 3.1+

Home Page: http://jelly.jonathan-geiger.com

License: MIT License

PHP 100.00%

jelly's People

Contributors

agentphoenix avatar banks avatar claudiuandrei avatar creatoro avatar dewos avatar jerfowler avatar leth avatar lokaltog avatar smgladkovskiy avatar vitch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jelly's Issues

Alias building while order_by

There is a method _field_alias in classes/jelly/core/builder.php

        // Alias to the column
        if ($meta = Jelly::meta($model) AND $field_obj = $meta->field($field) AND $field_obj->in_db)
        {
            $column = $field_obj->column;

            // We're 99% sure adding the table name in front won't cause problems now
            $join = $join_if_sure ? TRUE : $join;
        }

        return $join ? $alias.'.'.$column : $column;

In case of order_by method adds table_name to returning value and, for example,

column_name

becomes

table_name.column_name

but table prefix wont be added later, so we'll recieve a query like this:

SELECT `table_prefix_table`.`field` FROM `table_prefix_table` ORDER BY `table`.`field`

so query fails

Is it a jelly bug?

as_array()

Returning results as an array in method from documentation

$data = $posts->as_array(array('id', 'name', 'body'));

doesn't work

Jelly_Field_Image - transformations from one thumbnail applies to other

We have Image field with defined two or more thumbnails.

'image' => Jelly::field('image', array(
    'transformations' => array(
        'resize' => array(880, 200, Image::INVERSE),
        'crop' => array(880, 200),
    ),
    'thumbnails' => array(
        array(
            'prefix' => 'small_',
            'transformations' => array(
                'resize' => array(220, 50, Image::AUTO),
            ),
        ),
        array(
            'prefix' => 'cropped_',
            'transformations' => array(
                'crop' => array(250, 200),
            ),
        ),
    ),
)),

Then, while uploading a file, each thumbnail is generated not from the main image file, but from the image transformed by thumbnails defined before current. In the above example, last thumbnail will cropped from image with applied 'resize' => array(220, 50, Image::AUTO), transformation from previous "small_" thumbnail.

Is this intentional behavior? I think that each thumbnail should be generated from the base image (with applied main transformations), independently of the other thumbnails.

add load function to jelly builder

select() function always return Jelly_Collection
load() function always return Jelly_Model

I think it's better leave to developer to decide which return type he would like to use, instead using automated result type based on limit(1).

syntax example

// Get all posts
$posts = Jelly::query('post')->select();
// Get first post
$post = Jelly::query('post')->load();
// Get jelly model post
$post = Jelly::query('post')->where('title', '=', 'hello')->load();

This is useful when limit variable is based on user input.
For example

// Get post limit from url
$limit = (int) $this->request->get('limit');
// Get all posts
$posts =  Jelly::query('post')->limit($limit)->select();
// Show all post
foreach ($posts as $post)
{
    echo $post->text;
}

The code above wouldn't have problem even limit is 1, but it would have problem for current syntax since it would return jelly model instead of jelly collection.

And i think it's easy for developer to decide when he would like to use load or select.
It's just like find() and find_all() in official ORM module.

Thank you

Problem with the `_is_unique` rule

Jelly has a callback that checks the field value if it's unique. This check only runs when the field value is not NULL which respects the SQL standards. But if the field is not allowed to have NULL and the default value is an empty string (for example Jelly_Field_String) then this check will fail if there's more than one empty value in the database.

Wrong class extensions

It's impossibile to use benefits of Kohana's CFS without completly overloading classes.

The whole module should be reviewed for this issues.

file:
classes/jelly/core/builder.php

replace:
abstract class Jelly_Core_Builder extends Kohana_Database_Query_Builder_Select

with:
abstract class Jelly_Core_Builder extends Database_Query_Builder_Select

file:
classes/jelly/core/field/image.php

replace:
abstract class Jelly_Core_Field_Image extends Jelly_Core_Field_File

with:
abstract class Jelly_Core_Field_Image extends Jelly_Field_File

External validation is skipped if no data has changed

External validation will not run if no data is changed, which can be a problem when for example we have a model that has a field which is empty, but we want to update this field and set it as required.

In this case we could use external validation to check if the field is not empty, but this check will be skipped as the original value is empty and the new value is empty as well, so this results in no changed data.

Validation might use previously saved data in rare cases

This bug comes from the old-style validation system which doesn't build a new validation object on every check (however it may only be a bug in the new validation system). In result if you want to save two models after each other the validation might use the data that was saved previously.

Deleting related records in HasOne and HasMany associations

Hi!

Is there any possibility to set that the objects linked to the current object (by HasOne or HasMany association) were automatically deleted when current object is? I mean something like what you can find in ActiveRecord in Rails. (has_many :news, :dependent => :destroy).

If not, it would be nice if this functionality was implemented into Jelly. It could be declared like this:

'news' => Jelly::field('HasMany', array(
  'foreign' => 'news.author_id',
  'dependent' => 'destroy', // Rails-ish way to do this
)),

Image set without upload

Hi, I want to upload a photo (ultra big photo) but save in the database with Jelly with a CRON.

When I set the image as string of their path it never validates.

For example: "/home/ddd/image.jpg" or "image.jpg".

If I create a fake $_FILES object, the function "is_uploaded_file" doesn't pass.

There's a way to accomplish that?

Thanks.

Loading behavior with the same name as model

When creating query, Jelly automatically loads the builder (if exists) with the same name as the model. Have you thought about creating a similar mechanism for behaviors?

For example:
We have a model Model_Product and related builder called Jelly_Behavior_Product. Now, while instantiating Model_Product (Jelly::factory('Product'), Jelly::query('Product') etc.) mechanism described above would look if there is a behavior called Jelly_Behavior_Product and automatically load if exists. This would release us from the obligation to manually append $meta->behaviors(array(new Jelly_Behavior_Product)) in the model's initialize method.

Update class structure

I was thinking about making Jelly more Kodoc-friendly by updating comment headers and restructuring the project class structure to be more like the Kohana project and other modules. I.e. renaming all Jelly_Core_* classes to Kohana_Jelly_* and separating classes with @category tags. I recently did this to another project I'm working on, and I really think the folder structure is more logical and easier to understand.

A structure change like this will not change anything for the end user, because it only changes the extended classes.

What do you guys think about this? I'd be happy to perform the update if others agree.

$_with not behaving expectedly

When setting protected $_with = array('role'), I would expect it to perform a join, but instead it just selects model.role_id AS model.role.

Ideally, I think doing this:
$user = Jelly::query('user', 1)->select();
Should always add that join when $_with is set, so essentially doing this behind the scenes:
$user = Jelly::query('user', 1)->with('role')->select();

Deleting all the relationships is impossible

It's not possible to delete all relationships, because when Jelly tries to find out what has to be changed the current relationships and the changed relationships are the same, so array_diff will return empty here:

    // Are we adding or removing?
    if ($add)
    {
        $changes = array_unique(array_merge($current, $changes));
    }
    else
    {
        $changes = array_diff($current, $changes);
    }

Listing with joins

I want to make a list of posts with authors. So I've made a "belongsto" relationships in post model, but when I'm listing them Jelly generates additional select queries for every post (to get author's data).

Is it possible to generate just one query like: SELECT posts., authors. FROM posts p JOIN authors a ON (a.id = p.author_id)?

Move model related code to models in Auth driver.

Right now the Auth driver is an exact copy of ORM's Auth driver and there's some model related code in the controller. This should go into the models as it belongs there and it prevents the user to take advantage of some Jelly features, like setting a database to use.

manytomany field, has function doesn't return correct value with blank jelly model

Here is the example code,
user has many groups, and groups has many users

// Search for group that doesn't exist, returning blank 'group' jelly model
$group = Jelly::query('group')
    ->where('groupname', '=', 'somethingnotexist')
    ->load();

// Get logged in user
$logged_in_user = Auth::instance()->get_user();

// Return TRUE, when it should return FALSE
echo Debug::vars($logged_in_user->has('groups', $group));

Fix : on Jelly_Core_Field_ManyToMany has function

replace

foreach ($ids as $id)
{
    if ( ! in_array($id, $in))
    {
        return FALSE;
    }
}

return TRUE;

with

$result = FALSE;
foreach ($ids as $id)
{
    $result = in_array($id, $in);
    if ( ! $result)
        break;
}

return $result;

or
(bool) array_intersect($ids, $in);

Add optional prefix for thumbnails in Jelly_Field_Image

Right now the image field will force you to save your thumbs in a different directory with the same name.

Features needed:

  • optional prefix for thumbs
  • path should be optional for thumbs as well if prefix is set (if no path is set the path for the original will be used)

Enhance image upload

At the moment it's not possbile to refactor the original image, only the thumbnails and there's no way to set the quality of the saved images.

Can't add HasOne relationship

When trying to add a HasOne relationship like this:

    $model = Jelly::factory('author');
    $foreign = Jelly::factory('post');
    $foreign->save();
    $model->post = $foreign->id;
    $model->save();

It will fail, because Jelly_Core_Field_HasOne is not savable and looks for an array when setting the relationship:

if ( ! empty($value) AND is_array($value))

hash_with bug

When 'hash_with' in field password isn't set, hash() method returns NULL instead of plain password.
Fix: add return $password; in hash() method.

public function hash($password, Jelly_Model $model)
{
    // Do we need to hash the password?
    if ( ! empty($password) AND $this->hash_with AND $model->changed($this->name))
    {
        // Hash the password
        return call_user_func($this->hash_with, $password);
    }

    return $password;
}

Database group name

In some cases there won't be group 'default' in config file (eg. there will be insdtead 'production', 'development', etc.) -- Jelly should get group name from Database::$default (I assume that this variable have correct name).

Jelly_Core_Meta needs changes:
protected $_db = NULL;
(...)
public function db($value = NULL)
{
if (func_num_args() !== 0)
{
return $this->set('db', $value);
}

    return isset($this->_db) ? $this->_db : Database::$default;
}

Automatically deleting files when deleting an object

Referring to previous issue (#42) a good thing would be to be able to set that all uploaded files related to the currently deleted object will be deleted as well.

There are two fields that deal with handling file upload - Jelly_Field_Image and Jelly_Field_Field. My suggestion is to add additional property to each of them, that if set to TRUE will be responsible for deleting files when removing an object. As files, I mean:

  • Jelly_Field_File: file associated with this field
  • Jelly_Field_Image: pictures of all sizes

It should also be checked whether it is access to deleted files in case they didn't exist or was no access to them.

Further flexibility for Jelly_Field_Slug

Kohana's URL::title does a really good job in creating slugs, so it would be easy to use it, but I was thinking about having the ability of creating slugs that have folder like 'hierarchy' in them.

For example:
fist-part/second-part

Where the separator is - and the hierarchy separator is /.

The features needed:

  • allow folder-like hierarchy in slugs
  • configurable hierarchy-separator
  • ability to transliterate to ASCII

Auth get_user problem

for example user has many posts

// Get logged in user
$user = Auth::instance()->get_user();

// Create post with user as author, for example user create post about weather
$user->create_post($values);

/* On other page * /
$user = Auth::instance()->get_user();

// Get user posts
$posts = $user->posts->as_array('id', 'title')
// User still doesn't have weather post that we have created earlier (Incorrect)
echo Debug::vars($posts);

// Get user posts
$posts = $user->get('posts')->select()->as_array('id, 'title');
// If we using get syntax, will return correct result (all user posts)
echo Debug::vars($posts);

Multiple BelongsTo joins doesn't work

When relation name difference of table name, we have error in Jelly::alias();. Example:
I used your models from jelly-test, and change relation "role", to "action" in User model.

'action' => new Field_BelongsTo(array(
            'default' => 0,
            'foreign' => 'role'
        )),

Then:

Jelly::select('author')->with('action')->limit(1)->execute(); //This working fine;

But this:

Jelly::select('post')->with('author:action')->limit(1)->execute(); //Have error, cose Jelly search "action" as model.

When i try fix this problem, I came to that, architecture must be changed, cose Field_BelongsTo->with .. don't know about previous relations, and can't build valid aliases for the relation model

Type casting for Jelly_Field_Expression

I have an expression field which is the result of a mathematical expression, but jelly returns the result as a string.

If you could specify the type of an expression field, in terms of an existing jelly field type, it could use that field type to cast the value extensibly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.