Comments (8)
What SQL should it generate?
from red.
SELECT
person.*,
post.*
FROM
person JOIN post ON(person.id = post.author_id)
from red.
SELECT
person.*,
array_agg(post.*)
FROM
person JOIN post ON(person.id = post.author_id)
GROUP BY
person.id, person.name, ...
from red.
SELECT
array_agg(post.*)
FROM
post
GROUP BY
post.author_id
from red.
For some reason I was thinking about this last night and came to the conclusion that actually it might be of least surprise to the user if it actually did something like :
SELECT
post.*
FROM
person JOIN post ON(person.id = post.author_id)
And returns a ResultSeq of Post.
Which of itself is fairly useless, until you have a grep before the map such as:
Person.^all.grep( ?*.active).map({ .posts})
And get:
SELECT
post.*
FROM
person JOIN post ON(person.id = post.author_id)
WHERE
person.active
But just my ยข2
from red.
O think that would be perfect for a .flatmap
but I think it should return a Seq of Seqs...
Sent with GitHawk
from red.
I had this problem today:
use Red;
my $*RED-DB = database "SQLite";
#my $*RED-DB = database "SQLite", :database</Users/fernando/test.db>;
model MongerPM { ... }
model Monger {
has Int $!id is serial;
has Str $.name is column;
has MongerPM @.monger-pm is relationship{ .monger-id }
method pms { @!monger-pm.map: *.pm }
}
model PMGroup is table<pm_group> {
has Str $.city is id;
has MongerPM @!monger-pm is relationship{ .pm-id }
method mongers { @!monger-pm.map: *.monger }
method gist { "{ $!city }.PM" }
}
model MongerPM is table<monger_pm> {
has Int $.monger-id is referencing{ Monger.id };
has Str $.pm-id is referencing{ PMGroup.city };
has Monger $.monger is relationship{ .monger-id };
has PMGroup $.pm is relationship{ .pm-id };
}
#my $*RED-DEBUG = True;
Monger.^create-table;
PMGroup.^create-table;
MongerPM.^create-table;
my $*RED-DEBUG = True;
my $pm = PMGroup.^create: :city<Rio>;
my $monger = Monger.^create: :name<Fernando>;
MongerPM.^create: :$monger, :$pm;
#.monger-pm>>.pm.say for Monger.^all
#for Monger.^all -> $monger {
# for $monger.monger-pm.map: *.pm {
# .say
# }
#}
.pms.say for Monger.^all
i think relationships of model type objects should continue returning the model, but it could mixin a role that would store what relationship it was, so, on translate it could use that...
multi method translate(Red::AST::Value $_ where .type ~~ Red::Model, $context?) {
die "NYI: map returning a relationship";
}
from red.
Maybe we could use the same approach we did in #417 here.
from red.
Related Issues (20)
- Cannot find `pq` on Mac HOT 1
- Having issues while trying to modularise code HOT 9
- Totally broken on HEAD HOT 1
- How to pass creds for mysql db to Red tests? HOT 5
- Possible concurrency issue in query construction HOT 6
- Make docs use RETURNING HOT 1
- Failed to find dependencies: pq:ver<5>:from<native> HOT 1
- Add modularity HOT 2
- Error using Red. HOT 2
- Add support for "locking clause" on SELECT HOT 12
- Rakuize code and documentation HOT 2
- .year Method on PostgreSQL driver don't work HOT 5
- SparrowCI build fails HOT 1
- Regression in DateTime comparison operators on Pg HOT 7
- Unexpected behaviour of parameterised clause in `join-model` HOT 5
- Test fail: t/23-metamodel-model.rakutest line 62 HOT 7
- Tests fail on Rakudo v2024.03 HOT 13
- Implement SAVEPOINT (and friends.) HOT 3
- Make `.for-update`, `.skip-locked` a no-op on SQLite HOT 1
- EXISTS/NOT EXISTS as sub query HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from red.