Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master

This branch is 1190 commits ahead of cardmagic:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
lib
spec
tasks
History.txt
LICENSE
Manifest.txt
README.txt
Rakefile
TODO

README.txt

= dm-is-viewable

Adds simple SQL View-like functionality to DataMapper.  It helps keep your queries dry.

= Viewables
=== Before
@users = User.all(:active => true, :age.gt => 18, :gender => :female)

=== After
class User
  include DataMapper::Resource

 is :viewable

 # After the name symbol you can treat supply anything that would work in Resource#all
 create_view :legal_women, :active => true, :age.gt => 18, :gender => :female
 create_view :legal_people, :active => true, :age.gt => 18

 #... Your code here ...
end

@users = User.view :legal_women # :)

=== Further restricting results
@users = User.view :legal_women, :city => 'Los Angeles'
# => Only finds women in LA

@users = User.view :legal_people, :gender => :male
# => Finds dudes if thats what you are into.

# Remember, views restrict results so the following would return nothing
@users = User.view :legal_women, :gender => :male

# => returns nil, the query essentially became:
#    Select * from users where gender = 'female' and gender = 'male';

#Example of JOIN TODO

=== Complaints
<nasally_nerd_voice>
But sirs, a SQL View is a separate table like structure, not something definable in an object!??!1eleven.
</nasally_nerd_voice>

This is for an ORM, so views are mapped into the objects, besides you are probably accessing your true MySQL views with another DataMapper::Resource.
Something went wrong with that request. Please try again.