Comments (3)
I'm currently working on getting the docs complete.
You could do the following:
Model.join('athlete') //for a left join - or use .leftJoin(), rightJoin(), .innerJoin() or .outerJoin()
if you just want to prefetch relational data, use .include()
.
The arguments for .join()
and .include()
could be a:
String
(relation name)Array
with relation namesObject
where the key is the relation name. The value could by anything the.include()
method accepts (String
,Array
,Object
) - sub relations!
See includes-test.js
from openrecord.
so there's no method to fetch an association after the parent is loaded?
e.g. the example above model is 'Account' in the following (obviously unnecessary as is, but shows more of what i'm looking at) example:
Account.get(MY_ID).exec().then((account) => account.athlete.load())
or
Account.get(MY_ID).exec().then((account) => account.relations.athlete.load())
from openrecord.
With a has_many
relation, you could do the following:
Account.get(MY_ID).exec()
.then((account) => account.athletes.exec())
.then(athletes => console.log(athletes))
This currently only works with has_many
and belongsToMany
, because the relation object (empty array) has all conditions at hand. It's a preconfigured query like Athlete.where({account_id: 1234})
.
belongs_to
relations return null
for a record that isn't prefetched.
I've some ideas to solve this problem. But this is a breaking change, so another thing to address in v2
from openrecord.
Related Issues (20)
- Model.find() with empty argument has an unexpected return HOT 2
- Bugs when using offset / limit HOT 5
- How to initialize records from raw rows? HOT 2
- VScode Intellisense for auto generated models HOT 2
- create(data) but get null HOT 2
- Model.create({}) and Model.new({}) autoAttributes = true HOT 11
- ID conversion problem HOT 9
- mysql socketPath HOT 1
- Add documentation or examples to use with ldap HOT 4
- Publish a new release with latest dependency HOT 2
- How can i make raw sql query? HOT 1
- RangeError: Maximum call stack size exceeded HOT 1
- How to select SQL? HOT 2
- select_value as in activerecord HOT 12
- Please update CONTRIBUTING.md HOT 1
- Not returning complete record on create HOT 2
- How can one import/require the ValidationError class? HOT 1
- Help Wanted. Database query builder HOT 2
- Integer keys HOT 4
- has many through HOT 4
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 openrecord.