Module: N::RelationUtils
- Defined in:
- lib/n/db/mixins.rb
Overview
RelationUtils
A collection of general Relation utilities. Extend this method in your classes.
Instance Method Summary collapse
-
#count_targets_for_parent(pid, pclass, tclass, extrasql = nil) ⇒ Object
Count targets for the given parent.
-
#targets_for_parent(pid, pclass, tclass, extrasql = nil) ⇒ Object
Return the targets for the given parent.
Instance Method Details
#count_targets_for_parent(pid, pclass, tclass, extrasql = nil) ⇒ Object
Count targets for the given parent
146 147 148 |
# File 'lib/n/db/mixins.rb', line 146 def count_targets_for_parent(pid, pclass, tclass, extrasql = nil) return $db.count("SELECT COUNT(*) FROM #{tclass::DBTABLE} AS f, #{self::DBTABLE} AS r WHERE f.oid=r.tid #{extrasql}") end |
#targets_for_parent(pid, pclass, tclass, extrasql = nil) ⇒ Object
Return the targets for the given parent.
140 141 142 |
# File 'lib/n/db/mixins.rb', line 140 def targets_for_parent(pid, pclass, tclass, extrasql = nil) return $db.select("SELECT f.*, r.oid AS relid, r.create_time AS relct FROM #{tclass::DBTABLE} AS f, #{self::DBTABLE} AS r WHERE f.oid=r.tid #{extrasql}", tclass, [:relid, :relct]) end |