finding a record by other field values that primary key

1 view
Skip to first unread message

ElKlaaso

unread,
Nov 14, 2008, 9:41:51 AM11/14/08
to Reactor development
Hi,

I started using reactor 3 weeks ago, basically because it has good
performance, has a quite basic setup, and lets me extend it easily
with SQL if things are just to complicated or slow to implement in
Reactor itself.

I was wondering if there is an easier way to find a single record by
field values other then the primary key.

As far as i know at the moment, i have to use a gateway to find record
by other values, for example, if want to find a user by email and
password, it seems like i would have to do it something like this:

<cfset userQuery=userGateway.getByFields(email=arguments.email,
password=arguments.password)>

<cfif userQuery.recordCount eq 1>
<cfset user.setUserId(userQuery.userId) />
<cfset user.load() />
</cfif>

I find this quite verbose for functionality im likely to use quite
often.

I have a method that can get row one of the query, and populate a user
record with it. This would be quicker then the way described above.

But, it would be handy if reactor has a build in method for this so i
can do this with 1 line of code.. does this exist?

A solution would be to have a getByFields, that woul return 1 record,
and if it find more then 1, would throw an exception like
ToManyRowsException or MoreThenOneRowException.

Forgive me if this already exist or if im missing out on a great
'but'....

Greets,
Klaas-Jan Winkel

Tom Chiverton

unread,
Nov 18, 2008, 5:06:01 AM11/18/08
to reacto...@googlegroups.com
2008/11/14 ElKlaaso <k.wi...@gmail.com>:

> As far as i know at the moment, i have to use a gateway to find record
> by other values, for example, if want to find a user by email and
> password, it seems like i would have to do it something like this:

gateway.getByFields(a=1,b='ghd')
would also be useful for finding >1 records though.
gateway.getOneByFields(a=1,b='ghd') and gateway.getByFields(a=1,b='ghd') maybe ?

Mark - lets add this one to the list !

--
Tom

Klaas-Jan Winkel

unread,
Nov 18, 2008, 6:41:56 AM11/18/08
to reacto...@googlegroups.com
Is gateway.getOneByFields a proposed method for a new version of
reactor or does this actually exist?


klaas
--
Because you're so cute, i baked you a pony

Tom Chiverton

unread,
Nov 18, 2008, 11:31:11 AM11/18/08
to reacto...@googlegroups.com
2008/11/18 Klaas-Jan Winkel <k.wi...@gmail.com>:

> Is gateway.getOneByFields a proposed method for a new version of
> reactor

That, sorry :-)
Feel free to write up your request and this thread on trac.reactorframework.org

--
Tom

Tom Chiverton

unread,
Nov 19, 2008, 7:05:22 AM11/19/08
to reacto...@googlegroups.com
> Feel free to write up your request and this thread on trac.reactorframework.org

I've done it, don't worry.


--
Tom

Dutch Rapley

unread,
Dec 30, 2008, 11:30:56 AM12/30/08
to reacto...@googlegroups.com
This functionality already exists with createRecord().load()

Instead of passing the id field, you can pass a list of attributes

<cfset User = Reactor.createRecord('User').load(email=form.email, password = Hash(form.password)) />

If more than one record is returned, it throws an exception.

HTH

-Dutch
Reply all
Reply to author
Forward
0 new messages