-
-
Save karnauskas/4154896 to your computer and use it in GitHub Desktop.
Poor mans RA with dm-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
property :id, Seriaal | |
property :name, STring | |
has n, :bar | |
# Enumerate bar with name | |
# | |
# @return [self] | |
# if block given | |
# | |
# @return [Enumerator<Array>] | |
# otherwise | |
# | |
# @api private | |
# | |
def bar_with_name(query={}) | |
return to_enum(__method__) unless block_given? | |
bar.all(query).map do |bar| | |
yield [bar, name] | |
end | |
self | |
end | |
end | |
class Bar | |
belongs_to :foo | |
property :something | |
end | |
Foo.first.bar_with_name(:your => :restriction).each do |bar, name| | |
# do your stuff | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment