Some noob questions

8 views
Skip to first unread message

Haruki Zaemon

unread,
Feb 14, 2008, 7:42:53 AM2/14/08
to ambition.rb
First off, I know everyone else has said it, but this has got to be
the best darn project I've yet seen for Rails! anyway, on with my
questions:

1. Practically, what is the difference between entries() and to_a()?
Functionally they seem to behave the same.

2. Is it possible to construct a query involving joins that do an
inner join? I notice the syntax only seems to allow for outer joins.

3. I'm currently using the fact that association navigation implicitly
adds scoping to queries so that I can have a method such as
Student.current which is implement using ambition and then do
something like: School.first.students.current to return a list of
current students for a particular school. This only works however, as
long as I make Student.current also invoke a kicker. I wondering if
there's any chance the query builder could take into account any
current with_scope? Then I wouldn't need to explicitly call the
kicker.

Thanks in advance,

Simon

Matthew King

unread,
Feb 14, 2008, 9:52:18 AM2/14/08
to ambit...@googlegroups.com
On Feb 14, 2008, at 6:42 AM, Haruki Zaemon wrote:

> 1. Practically, what is the difference between entries() and to_a()?
> Functionally they seem to behave the same.

They're the same method in Enumerable, which is why they're the same
in ambitious-activerecord.

http://ruby-doc.org/core/classes/Enumerable.html#M003149


Haruki Zaemon

unread,
Feb 14, 2008, 2:07:21 PM2/14/08
to ambition.rb
*slaps* forehead! :)

Haruki Zaemon

unread,
Feb 14, 2008, 5:23:41 PM2/14/08
to ambition.rb
Here's a quick-and-dirty patch to ambitious-activerecord to do exactly
this

> 3. I'm currently using the fact that association navigation implicitly
> adds scoping to queries so that I can have a method such as
> Student.current which is implement using ambition and then do
> something like: School.first.students.current to return a list of
> current students for a particular school. This only works however, as
> long as I make Student.current also invoke a kicker. I wondering if
> there's any chance the query builder could take into account any
> current with_scope? Then I wouldn't need to explicitly call the
> kicker.

Index: ambitious-activerecord-0.1.0/lib/ambition/adapters/
active_record/association_collection.rb
===================================================================
--- ambitious-activerecord-0.1.0/lib/ambition/adapters/active_record/
association_collection.rb (revision 0)
+++ ambitious-activerecord-0.1.0/lib/ambition/adapters/active_record/
association_collection.rb (revision 0)
@@ -0,0 +1,31 @@
+module Ambition
+ module Adapters
+ module ActiveRecord
+ module AssociationCollection
+ def self.included(base)
+ base.class_eval do
+ alias :method_missing_without_ambition :method_missing
+ alias :method_missing :method_missing_with_ambition
+ end
+ end
+
+ protected
+
+ def method_missing_with_ambition(method, *args, &block)
+ result = method_missing_without_ambition(method, *args,
&block)
+ if result.is_a? Ambition::Context then
+ scope = construct_scope
+ find = scope[:find]
+ conditions = find[:conditions]
+ (result.clauses[:select] ||= []) << conditions unless
conditions.nil?
+ order = find[:order]
+ (result.clauses[:sort] ||= []) << order unless order.nil?
+ limit = find[:limit]
+ (result.clauses[:slice] ||= []) << limit unless
limit.nil?
+ end
+ result
+ end
+ end
+ end
+ end
+end
Index: ambitious-activerecord-0.1.0/lib/ambition/adapters/
active_record.rb
===================================================================
--- ambitious-activerecord-0.1.0/lib/ambition/adapters/
active_record.rb (revision 37)
+++ ambitious-activerecord-0.1.0/lib/ambition/adapters/
active_record.rb (working copy)
@@ -1,5 +1,6 @@
require 'ambition'
require 'active_record'
+require 'ambition/adapters/active_record/association_collection'
require 'ambition/adapters/active_record/query'
require 'ambition/adapters/active_record/base'
require 'ambition/adapters/active_record/select'
@@ -9,3 +10,4 @@

ActiveRecord::Base.extend Ambition::API
ActiveRecord::Base.ambition_adapter =
Ambition::Adapters::ActiveRecord
+ActiveRecord::Associations::AssociationCollection.send :include,
Ambition::Adapters::ActiveRecord::AssociationCollection

Haruki Zaemon

unread,
Feb 14, 2008, 5:26:52 PM2/14/08
to ambition.rb
FWIW, I tried signing up to lighthouse to post this as a patch but I
kept getting:

Application error

Change this error message for exceptions thrown outside of an action
(like in Dispatcher setups or broken Ruby code) in public/500.html

Chris Wanstrath

unread,
Feb 16, 2008, 6:05:11 AM2/16/08
to ambit...@googlegroups.com
This patch looks cool, but could you also send an accompanying test?

Thanks for the contribution. I invited you to GitHub -- why don't you
fork http://github.com/defunkt/ambition and commit your changes that
way. Then I can `git pull` and grab them with ease.

- Chris


--
Chris Wanstrath
http://errfree.com // http://errtheblog.com
http://github.com // http://famspam.com

Haruki Zaemon

unread,
Feb 17, 2008, 5:25:25 AM2/17/08
to ambition.rb
Yup. I intended to get to some tests. Will sign up to GitHub and get
cracking.

Haruki Zaemon

unread,
Feb 17, 2008, 6:11:27 AM2/17/08
to ambition.rb
My fork can be found at http://github.com/harukizaemon/ambition

On Feb 16, 10:05 pm, "Chris Wanstrath" <ch...@ozmm.org> wrote:
> This patch looks cool, but could you also send an accompanying test?
>
> Thanks for the contribution.  I invited you to GitHub -- why don't you
> forkhttp://github.com/defunkt/ambitionand commit your changes that
> way.  Then I can `git pull` and grab them with ease.
>
> - Chris
>
Reply all
Reply to author
Forward
0 new messages