Month: September 2011

Uniqueness in Fuel Models

As a part of broadening my horizons, I’m back to working with Fuel, a framework that has a familiar feel to some of the ones I’ve used in the past but has some extra “oomf” from new features and PHP 5.3-ness.

I was working in my models the other day and had a need for uniqueness – I wanted to be sure that the object I was pushing into the database didn’t match any other one. I went through the docs and didn’t see anything about it and a glance through the source didn’t turn up anything either. So, as an alternative, I came up with a method I put in my base model:

[php]
class Model_Base extends OrmModel
{
public function isUnique($modelObject)
{
$modelType = get_class($modelObject);
$found = $modelType::find(‘all’,array(
‘where’ => $modelObject->to_array()
));
return (count($found)>0) ? false : true;
}
}
[/php]

The code above finds the class name (the model the object is made from) and tries to find anything with exactly the same properties. The “to_array()” method is something Fuel has to translate objects into handy arrays.

Fuel ORM docs

Advertisement

The Joind.in & I

By now I’m sure a lot of the folks reading the posts from this blog know of the site I’ve helped shape over the past few years, Joind.in. It’s become most successful in PHP circles, but has branched out into other communities, both tech and non-tech. Not too long after the project started up, it was decided to open source the code and pull in contributions from whoever offered their time. I personally feel that, for a first out of the box open source project for me, it’s turned out well and has a great, active community around it. I’ve learned a lot working on not only the code but in management of the project as well.

I’m taking a break from all of this for now though. I know, Joind.in has been my baby for the last few years, but I’ve been feeling a little burnt out on it the last few months and I’m starting to feel like it’s having a negative impact on the project. My plan is to take a few months to regroup myself and pull my head out of the code and maybe even get a better, broader picture of what the project could become. My priorities are shifting towards another project I’ve been putting in some time on (no hints yet) that I hope can be a good tool for a similar community.

The management of the project is being put in capable hands, though – no worries there. Lorna will be the gatekeeper for all things Joind.in. She’ll be handling both the site and the open source project in their day to day needs. I’ll still be lurking around in the same places, but I won’t be as active in the project as I have been.

Thank you to the community that has made the site everything it is and I know it will grow even more in the months to come. Thanks for your contributions, both in code and even just in kind words. Please keep them coming and if you’re a fan or contributor of the project, ask Lorna if there’s a helpful hand you can lend. I know she’d appreciate it.

UPDATE: You can also see Lorna’s post here.