Hey @qszhu, sorry for the late response. You can do this:
.join(author: true, &.select(User))
This would effectively select all the fields of the author with proper table naming author.
instead of users.
I am not really getting how to make this work.
(first time I am trying to use a database instead of flat files)
what I would like to do is:
p headings[0].book.title
The code...
(sqlite)
CREATE TABLE book (
book INTEGER PRIMARY KEY,
title TEXT NOT NULL
);
CREATE TABLE heading (
heading INTEGER PRIMARY KEY,
title TEXT NOT NULL,
page INTEGER NOT NULL,
book INTEGER NOT NULL,
FOREIGN KEY (book) REFERENCES book(book)
);
class Models::Book
include Onyx::SQL::Model
schema book do
pkey book : Int64
type title : String, not_null: true
end
end
class Models::Heading
include Onyx::SQL::Model
schema heading do
pkey heading : Int64
type title : String, not_null: true
type page : Int32, not_null: true
type book : Book, not_null: true, key: "book"
end
end
headings = Onyx::SQL.query(Models::Heading.join(book: true, &.select(Models::Book)))
pp headings
The error I get when trying the above
Error in src/mini_index.cr:73: no overload matches 'Models::Heading.join', book: Bool
Overloads are:
- Onyx::SQL::Model::ClassQueryShortcuts(T)#join(table : String, on : String, as _as : String | ::Nil = nil, type : Onyx::SQL::Query::JoinType = :inner)
- Onyx::SQL::Model::ClassQueryShortcuts(T)#join(reference : T::Reference, on : String | ::Nil = nil, as _as : String = reference.to_s.underscore, type : Onyx::SQL::Query::JoinType = :inner)
- Onyx::SQL::Model::ClassQueryShortcuts(T)#join(reference : T::Reference, klass, *, on : String | ::Nil = nil, as _as : String = reference.to_s.underscore, type : JoinType = :inner, &block)
headings = Onyx::SQL.query(Models::Heading.join(book: true, &.select(Models::Book)))
I can work around it like this
headings = Onyx::SQL.query(Models::Heading.all)
books = Onyx::SQL.query(Models::Book.all)
pp books.select {|b| b.book == headings[0].book.try(&.book)} .first.title
Does anyone have any idea of what I am doing wrong?
Foo(Specific)
i can emit it, then make a new Foo(All)
from that and emit it too. Not ideal but it's okay
crystal
frameworks are compiled this way
cloud
and I have
ID | Language | Framework | Concurrency_256 | Concurrency_512 | Concurrency_1024 | Concurrency_4096 |
---|---|---|---|---|---|---|
0 | crystal | toro | 170684.92 | 169264.44 | 160203.22 | 145212.05 |
1 | crystal | grip | 155543.15 | 153499.32 | 143572.64 | 133531.28 |
2 | crystal | kemal | 155346.53 | 154275.05 | 148661.21 | 133866.99 |
3 | crystal | onyx | 5897.08 | 5694.81 | 5712.44 | 5943.12 |
4 | crystal | lucky | 1447.6 | 1452.64 | 1483.73 | 1439.16 |
5 | crystal | orion | 143488.53 | 140997.04 | 132082.26 | 123590.98 |
6 | crystal | router.cr | 170592.56 | 169353.18 | 162565.71 | 146515.72 |
7 | crystal | amber | 148885.5 | 147097.63 | 141702.92 | 128744.99 |
8 | crystal | athena | 136373.64 | 131619.22 | 123065.62 | 106287.44 |
9 | crystal | shivneri | 25350.55 | 26668.65 | 21811.13 | 25059.03 |
10 | crystal | spider-gazelle | 168117.54 | 167475.93 | 160398.59 | 143195.63 |