class Person < ActiveRecord::Base belongs_to :parent, class: Person has_many :children, class: Person, foreign_key: :parent_id has_many :grandchildren, class: Person, through: :children, source: :children end
Tuesday, August 26, 2014
has_many :grandchildren trick
Labels:
Ruby on Rails
Monday, August 25, 2014
Little bit ruby
% Notation
%q[ ] # Non-interpolated String (except for \\ \[ and \]) %Q[ ] # Interpolated String (default) %r[ ] # Interpolated Regexp (flags can appear after the closing delimiter) %i[ ] # Non-interpolated Array of symbols, separated by whitespace %I[ ] # Interpolated Array of symbols, separated by whitespace %w[ ] # Non-interpolated Array of words, separated by whitespace %W[ ] # Interpolated Array of words, separated by whitespace %x[ ] # Interpolated shell command
Labels:
Ruby
Sunday, August 24, 2014
Little bit about Graphs
simple
- no multiarcs and loopnon-simpl
(pseudog
) - multiarcs and loopcomplete
- each node conect beetwen each other directlyconected
- directly or nondirectli all nodes are conectedtree
- conected graph without circlespanning tree
- tree with (nodes-1 == arcs), min arcs for connect all nodesisomorphick
- graph when (arcs == nodes)sub
- part of graphActiveSupport::Inflector
ActiveSupport::Inflector - transforms words from singular to plural, class names to table names, modularized class names to ones without, and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept in inflections.rb.
Labels:
Ruby,
Ruby on Rails
Friday, August 22, 2014
PostgreSQL: array field
If we have array field in postgresql (like `tags`), we can use it for search as well:
- search records which contain `tag`
`ruby` = ANY(tags)
- search through array with tags
`{ruby, python, java}` && tags
- all tags should be equal `ruby`
`ruby` = ALL(tags)
- search records which contain `tag`
`ruby` = ANY(tags)
- search through array with tags
`{ruby, python, java}` && tags
- all tags should be equal `ruby`
`ruby` = ALL(tags)
Labels:
PostgreSQL
Subscribe to:
Posts (Atom)