Sha256: c85b7d6e01f96af7a95c1a2d1d5b306460d3ce0e6105aad96dc100b428979ca1

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

##
## This example realises a 1:n relation  using  a `embedded`property
#
## Its implemented in modelfiles located in spec/model
#  and runs in the test environment.
##
require 'bundler/setup'
require 'zeitwerk'
require 'arcade'

include Arcade
## require modelfiles
loader =  Zeitwerk::Loader.new
loader.push_dir ("#{__dir__}/../spec/model")
loader.setup

## clear test database

databases =  Arcade::Api.databases
if  databases.include?(Arcade::Config.database[:test])
  Arcade::Api.drop_database Arcade::Config.database[:test]
end
Arcade::Api.create_database Arcade::Config.database[:test]

## Universal Database handle
DB = Arcade::Init.connect 'test'

## ------------------------------------------------------ End Setup ------------------------------------- ##
##
## We are realising  a self referencing  relation
##  name -->   children
#


Ex::NewNames.create_type                              # initialize the database
                                                      # spec/models/ex/new_names.rb
                                                      # Put same names into the database
table = %w( Guthorn Fulkerson Sniezek Tomasulo Portwine Keala Revelli Jacks Gorby Alcaoa ).map do | name |
  Ex::NewNames.insert name: name, age: rand(99)
end
                                                      # Connect randomly
children = (0..6).map{ | i | table[-i].rid    }
puts children
i = 0
table.each.with_index do  | n, i |
   n.update  children: [ children[i] &.rid, table[ rand(10)+5] &.rid].compact
end

puts "-------------------- raw data ---------------------------"
puts Ex::NewNames.all false

puts "--------------- Parent and Children ---------------------"

children_query  = Ex::NewNames.query projection:  ['name as parent', 'children[age]']
puts children_query.query

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arcadedb-0.5.0 examples/relation_1__n.rb
arcadedb-0.4 examples/relation_1__n.rb
arcadedb-0.3.3 examples/relation_1__n.rb