creatoro / jelly Goto Github PK
View Code? Open in Web Editor NEWThis project forked from jonathangeiger/kohana-jelly
A flexible ORM for Kohana 3.1+
Home Page: http://jelly.jonathan-geiger.com
License: MIT License
This project forked from jonathangeiger/kohana-jelly
A flexible ORM for Kohana 3.1+
Home Page: http://jelly.jonathan-geiger.com
License: MIT License
See title.
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?
Returning results as an array in method from documentation
$data = $posts->as_array(array('id', 'name', 'body'));
doesn't work
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.
Hi, just wanted to know if it's (pretty)stable to use this on my new live project?
Thank you
Hashing performe before validation in Jelly_Field_Password.
Therefore, we get incorrect validation results .
See issue here.
Credit goes to biakaveron.
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
protected function _db($db)
-> protected function _db($db = NULL)
See title.
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.
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 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.
Upload validation should be skipped if nothing is uploaded as all fields are optional until they are not explicitly defined to be required.
Upload is not working anymore because Validation will not modify the values anymore, so the database receives the content of the $_FILES
array instead of the uploaded filename.
If no default value is set the first value of the choices array will be the default. The only problem that the field selects the value, rather then the key of the element.
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.
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
)),
The current implementation of the Field_Image class is bloated and should be rewrited.
You can find my proposal in the 3.1/develop-creatoro-unstable branch (relevant commit loonies/kohana-jelly@440ed18), just to get an idea.
Note: I did this before #24, so didn't took related changes into account
See issue here.
Credit goes to biakaveron.
Copy and modify the ORM driver for Auth.
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.
As described in title.
The current implementation of Field_File::_upload
is inconsistent. Namely, Field_File::_upload
will sometimes return the Validation object and sometimes boolean. Classes that use this method (e.g. Field_Image) can't rely on this implementation (see Field_Image@L126).
Fix here loonies/kohana-jelly@6437a6c
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.
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.
For example
user has many posts, post has many comments
Is it possible with jelly to do thing like this?
//Get all comments by user
$user->posts->comments;
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();
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);
}
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)?
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.
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);
The is_unique
rules is still using some old aliases for validation.
Right now the image field will force you to save your thumbs in a different directory with the same name.
Features needed:
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.
This is because of the update that made file validation compatible with the new validation system.
See here.
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))
Simple feature, but missing atm.
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;
}
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;
}
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 fieldJelly_Field_Image
: pictures of all sizesIt should also be checked whether it is access to deleted files in case they didn't exist or was no access to them.
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:
Update docs to reflect the changes.
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);
In Jelly_Core_Builder
the following lines change the result of a delete to NULL if no events were run:
// Trigger after_query callbacks
if ($meta)
{
$meta->events()->trigger('builder.after_select', $this);
}
This will results in a failed model test: test_save_empty_model
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.