SOFA ticket #1
Unlike hibernate or Rails’ ActiveRecord ORM Sofa isn’t an intrusive framework. Accessing a relational property won’t get you other things that what you’ve put into. Currently it’s possible to populate a property by setting “auto-fetch=’on’” or by doing a “fetch Object.property” in a load request. But we needed a way to do a “just in time” fetching. The best one we’ve found was to mount an object into the SofaManager so then we could execute a new opertation on it. Here’s an example :
private var user:User; var sofaManager:SofaManager = SofaSession.getSession(); // We load the user with id 1 user = sofaManager.createQuery("load User where User.id = :id") .setIntegerArgument("id", 1) .execute(); trace(user.pictures); // will output null //beacause we didn't set auto-fetch to 'on' user.pictures isn't set yet. //we mount the object and fetch its pictures user = sofaManager.mount(user) .createQuery("fetch User.pictures") .execute(); trace(user.pictures); // will output an ArrayCollection
This sample code is equivalent to :
user = sofaManager.createQuery("load User where User.id = :id;") .append("fetch User.pictures") .setIntegerArgument("id", 1) .execute();
SOFA is currently under hard development and we’re not able to give a release date yet.
Introducing SOFA an Adobe Air ORM for SQlite
We’re currently working on an ORM for Air/SQlite, it will be released as an open source project in a few weeks. It has support for nested fetching, cascade saving and deleting, many to many + one to many relationship, inheritance, formulas and more. It’s not an activerecord pattern, it’s more like hibernate. By the way, it requires some xml configuration files and currently has no support for conventions… maybe in the next release. Activerecord is a wonderfull pattern but we wanted it to provide nested fetching and cascade saving with a “no more line” way. Here is a quick example of the SofaQL :
Family family = sofaManager .createQuery("load Family <=> f where f.id = :id; fetch Family.people") .setIntegerArgument("id", 1) .execute();
will produce :
Handle LOAD : LOAD Family executing : SELECT Family.ID AS Family_0_id, Family.NAME AS Family_0_name FROM FAMILY Family WHERE Family.ID = 1 fetching : fetch Family.people executing : SELECT Person.ID AS Person_0_id, Person.NAME AS Person_0_name, Person.ID AS Person_0_id, Person.FAMILY_ID AS Person_0_familyId FROM ( ( People Person INNER JOIN SuperPeople SuperPerson ON SuperPerson.ID = Person.ID ) Person ) Person WHERE Person.FAMILY_ID = 1
result = (Family)#0 id = 1 name = "pezel" people = (mx.collections::ArrayCollection)#1 filterFunction = (null) length = 1 list = (mx.collections::ArrayList)#2 length = 1 source = (Array)#3 [0] (Person)#4 familyId = 1 id = 1 name = "arnaud" uid = "A126F4E4-D083-68E2-0F34-723C76CA1A9C" sort = (null) source = (Array)#3
Here Person extends SuperPerson, the last query is a little dirty but it allows to handle n-level inheritance on one to many and many to many relationships.
Oh ! and Sofa means “Simple orm for air”. It’s also the place where this project started.
It’ll probably be delivered on google code quickly. Stay tuned !




