Mailinglist Archive: opensuse-ruby (32 mails)

< Previous Next >
Re: [opensuse-ruby] Arel examples / documentation?
On Mon, 19 Mar 2012 12:51:50 +0100
Stephan Kulow <coolo@xxxxxxx> wrote:


I'm evaluating porting OBS to rails 3 and while there are
tons of annoying problems, that are ugly to fix but are "just work", I
have a real problem with the now deprecated find functions.

Let's take an example:

attribs.find(:first, :joins => "LEFT OUTER JOIN attrib_types at ON
attribs.attrib_type_id = LEFT OUTER JOIN attrib_namespaces an ON
at.attrib_namespace_id =", :conditions => [" = BINARY ? and = BINARY ? and attribs.binary = BINARY ?", name, namespace, binary])

Ugh, really horrible. I think that it must be written better. Do you consider
definiting Associations?

It should help a lot.

That's find_attribute and worked ok in rails 2.3 - it's a pretty huge
join and a rather useless big result, but ok.

Now with rails 3, find(:first) is not only deprecated but also joins
set the result to readonly, so I can't do an update to Attrib.

.find(:first,...) => .first(...)

What I did (after a lot of trial and error and googling around was):

a = attribs.joins(:attrib_type =>
:attrib_namespace).where(" = BINARY ? and = BINARY ? and ISNULL(attribs.binary)", name,
a = attribs.where(:id => if a && a.readonly?

yes, this is one time joins. I think it is useful only if there is no logic
connection..but attribs_type and attrib looks connected for me.

I found the existing documentating I could find rather unpleasant, they
always only cover simple cases or examples I don't understand ;(

You can ask here, we have quite lot of knowledge about rails inside company.

Does anyone have a recommendation for such "at the limits" cases?

Well, for such at limits ( which I don't see in yoyur case ), I recommend to
use pure sql command. For often used restrictions I recommend to use scopes -

I think that whole querying guide can help you.


Greetings, Stephan

To unsubscribe, e-mail: opensuse-ruby+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse-ruby+owner@xxxxxxxxxxxx

< Previous Next >