kla/php-activerecord — pull request #303 by Iazel (2013-04-25 21:00:32+00:00)
Title: has_many_through and is_valid fixes

has_many_through rely on other relationship to get the correct keys, but this means that every relationship of this kind must reside both in model A and model B.
An example from [foo_helper](test/helpers/foo.php):
```php
class User extends \ActiveRecord\Model {
static $has_many = array(
array('user_newsletters'),
array('newsletters', 'through' => 'user_newsletters'),
array('active_services'),
array('services', 'through' => 'active_services')
);

}

class Service extends \ActiveRecord\Model {
static $has_many = array(
array('active_services', 'foreign_key' => 'serv_id'),
array('users', 'through' => 'active_services')
);
}
class ActiveService extends \ActiveRecord\Model {
static $belongs_to = array(
array('user'),
array('service')
);
}
```

As you can see, the foreign key in active_services is "serv_id". Then User model will use that key for joins.
Plus, is possible use this kind of relationship with "joins" option:
```php
# code is an attribute of services
User::all( array('joins' => array('services'), 'conditions' => 'code = "daily_mail"') );
```

--------------------------

Model's `is_valid` and `is_invalid` have been fixed. Now they do not revalidate model at each call, but only when validation is required (ex: first time, or when an attribute has been modified). This methods accept a parameter that if `true` will run validations; useful only when a virtual attribute change and is used in some validations (because that can't be tracked).

---------------------------

Test included, for more information see them: [HasManyThrough](test/HasManyThroughTest.php) - [Validations](test/ValidationsTest.php)