Skip to content

Instantly share code, notes, and snippets.

@veganstraightedge
Created August 19, 2009 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veganstraightedge/170153 to your computer and use it in GitHub Desktop.
Save veganstraightedge/170153 to your computer and use it in GitHub Desktop.
My first rails (1.1.6) model
class Zine < ActiveRecord::Base
validates_presence_of :title, :downloads
has_many :tag
def self.latest
find(:first,
:select => "id",
:order => "id DESC")
end
def self.recent(limit = 5)
find(:all,
:select => "id, title, subtitle, author",
:limit => limit,
:order => "id DESC")
end
def self.tagged_zine_list(tag)
find(:all,
:select => "DISTINCT tags.zine_id, tags.tag, zines.id, zines.title",
:conditions => ["tags.tag = ?", tag],
:joins => "INNER JOIN tags ON zine_id = zines.id")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment