Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify value automatically, using callback, like ORM's filter() #55

Open
taai opened this issue Aug 2, 2012 · 2 comments
Open

Modify value automatically, using callback, like ORM's filter() #55

taai opened this issue Aug 2, 2012 · 2 comments
Labels

Comments

@taai
Copy link

taai commented Aug 2, 2012

In Kohana_ORM is possible to run a callback function that modifies the value when setting it on __set(). This is the same as using adaptors in Leap.
But I think that it's not worth to create a custom adaptor class wich calls another class, instead of calling that another class in first place.

Example is the password hashing with Auth::instance()->hash('password1') - with Kohana_ORM you can define the callback in the Model like this:

<?php
public function filters()
{
    return array(
        'password' => array(
            array(array(Auth::instance(), 'hash'))
        )
    );
}

And you can define any callback functions there - even from the same Model.

As I have said earlyer, I find Leap potentialy very powerful, but it lacks of functionality that has in Kohana_ORM, and Leap should have all the functionality that has Kohana_ORM to be able to compete with it.

I have spent days trying to set everything up with Leap, but I'm stuck with all these functionalities missing from Kohana_ORM...

I hope that you will agree to implement all these things.

@bluesnowman
Copy link
Member

Yes, I will be happy to get this added. This actually has been something that was in development but because we hadn't finished implementing it, I removed them because some were getting confused (thinking that it was implemented). I will totally agree with you as to making this apart of the project.

We are very thankful for you feedback.... It is very helpful in letting us know what is important to others and what things to focus on next.

@taai
Copy link
Author

taai commented Aug 3, 2012

To do this I have to know how exactly the structure is built. Can you tell me if I'm right or not?!

There are 4 ways how the value is set:
1 internally - values right from database
2 from an adaptor
3 from alias
4 from your code (normal usage)

What first 3 (and also 4th) have in common? - They all use similar code like $model->fields[$column]->value

Possible solutions

Create another set-type:
1 "internal_value" that should be changed in many files
2 "user_value" that should be changed in "field.php" and "model.php" files
Currently there are "value" and "modified" types. Look here ( https://github.com/spadefoot/kohana-orm-leap/blob/3.2/master/classes/base/db/orm/field.php#L111 ) to understand what I'm talking about.

So, the first 3 ways would either set value like $model->fields[$column]->internal_value, or when the values would be set from/to Model, it will set value like $this->fields[$column]->user_value.

Any comments about this approach? And which variant to make - 1st or 2nd? And what would be the best name for that set type?
And if you agree that this is ok, then I could write a code that's doing these modification callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants