-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The relationship method on a undefined method should return an alias of the relation type #9
Comments
if its an Array, its returning a |
Not a FakeSeq, but a ResultSeq |
model Post {
has UInt $!author-id is referencing{ Person.id };
has Person @.author is relationship{ .author-id };
}
Post.author; # returns a Person::ResultSeq :of() an alias named author
Post.author.map( *.id ); # Seq of UInt
Post.all.grep: { .author.name eq “FCO” };
Post.new.author; # returns a Person::ResultSet |
How can I know if I should continue on the ResultSeq chain or if I have to get the values and return a true Seq? |
The Person.all # returns an Person::ResultSeq (:of(Person))
.grep({ .name.starts-with("F") }) # adds an "WHERE name like 'F%'" on the query
# and return another Person::ResultSeq
.flatmap( *.posts ) # now it returns a Post::ResultSeq
# adding a join with the Person
.grep( *.title.chars == 5 ) # adds "WHERE LENGTH(title) = 5"
.map( *.body ) # returns an Red::Default::ResultSeq of Str
# Str doesn't Model, so the next call
# will run the query
.elems
; SELECT
post.body
FROM
person JOIN post ON(post.author_id = person.id)
WHERE
person.name like 'F%'
AND
LENGTH(post.title) = 5
; |
It's now possible to call the |
if you call |
but its automatic if you try to consume the seq |
The text was updated successfully, but these errors were encountered: