relationships,loopbackjs , What's the difference between embedsMany and hasMany in Strongloop loopback


What's the difference between embedsMany and hasMany in Strongloop loopback

Question:

Tag: relationships,loopbackjs

At first sight they seem to do the same thing: define a one-to-many relation So why would you choose one or another?


Answer:

EmbedsMany - a model that embeds many instances of another model; for example, a Customer can have multiple email addresses and each email address is a complex object that contains label and address. A hasMany relation builds a one-to-many connection with another model.

EmbedsMany embeds all child objects in the same parent object, HasMany stores child objects separately and has a property as the foreign key to reference the declaring model.


Related:


LoopBack: How to Dynamically Create Custom REST Endpoints In Code (On The Fly)


rest,dynamic,endpoint,loopbackjs,strongloop
We are using the LoopBack REST framework to expose our database (and business logic). We need to allow our customers to create custom tables in the database (single and multi-tenant) which can be accessed via a REST endpoint. All customers need to use the same common (production) REST endpoints which...

Remote method for updating all records


loopbackjs,strongloop
I try to make a custom endpoint, which adds a bonus to all employee. And retorns all the employee records, just like the get endpoint. Something like /employees/bonus As I understand; I should make a remote method for this: common/models/employee.js Employee.bonus = function(cb){ // logic comes here cb(null,"") } Employee.remoteMethod(...

How do I access loopback data in the server?


javascript,node.js,socket.io,loopbackjs
I am currently using loopback (http://loopback.io/) to run an application, while most of the data is accessed on the front end using the angular SDK I also have a socket connection where I'd like to access this data. In server/server.js I've got var loopback = require('loopback'); var app = module.exports...

How Can I Return a Random Object in Loopback?


node.js,loopbackjs
I'm using loopback to build an application, and would like to write a custom remote method which returns a random model instance from the database. Is there a way to do this using the built-in ORM? Thanks!...

Doctrine one-to-many relationship AND many-to-one


php,symfony2,doctrine2,cascade,relationships
I have two tables. I want to set up a one-to-many relationship, but also a many-to-one relationship. A Page can have one Background - this is the background of the page. A Page can also have many Backgrounds - this is a collection of user-uploaded backgrounds from which one will...

Android Native FB Login with Loopback.io and Passport.js?


node.js,facebook,loopbackjs
I am building a android client for my app which already has a web client and uses loopback-component-passport for FB authentication. I am able to successfully get the access_token from FB through my Android App. I figured out that the default passport component with loopback works by doing a GET...

Laravel/Eloquent save validation with parent/child relationships


laravel,eloquent,relationships
I have a parent model which must never exist without at least one associated hasMany relation. I am attempting to write validation for the model to ensure this never happens. public static function boot() { parent::boot(); // reject model with no children if (count($workflow->children) === 0) { throw new RuntimeException("need...

What is the shorter verb for “establishing a many-to-many relationship”?


many-to-many,terminology,relationships,relational-algebra
When we establish a one-to-one or many-to-one relationship, we can call it mapping. For example, we map a spouse to his/her spouse or each child to its parent. But what would be the verb singifying an establishment of a many-to-many relationship, underlining that it is not a 1+ to 1...

Loopback - Include a Relation's Computed Properties


javascript,node.js,loopbackjs
I have a loopback app and I'd like to be able to include computed properties from relations in an API call. For example, say I have an apartment model and an address model. The address has properties city and state. I'd like to make one call, to the apartment model,...

findOrCreate in PersistedModal


loopbackjs,strongloop
I am using loopback. I wish to create record if it doesn't exist. I used Modal.findOrCreate method to maintain uniqueness but its showing me error of findOrCreate is not a function but Docs show it is. What I tried was. Poet.findOrCreate({where: {name: query.name}}, {name:query.name},function(response){ console.log(response); }); I am editing question...

passing callback or promise to the different module , which one is better and efficient?


callback,promise,loopbackjs
In my application, I am passing callback to different module and so on. Same thing I am able to achieve using bluebird promise. According to best code practice, which one is better?...

Getting joined data from strongloop/loopback


node.js,loopbackjs,loopback
How can I get data from two joined tables? Suppose, there are two models called Category (CategoryId, CategoryName) and Product(ProductId, ProductName, CategoryId), Is there a way to get a result like:(ProductId, ProductName, CategoryId, CategoryName)

Loopback return an existing record on PU/UPSERT


postgresql,loopbackjs,upsert
I have the following PostGreSQL Locations table: -------------------- | ID | Name | -------------------- | 1 | Kitchen | -------------------- | 2 | Bedroom1 | -------------------- ID is a sequential PQ and Name has a unique constraint. Locations.json Name property has "index": { "unique": true }, And Locations.js includes Location.validatesUniquenessOf('Name');...

Core Data to-one relationship returns NULL


ios,core-data,nspredicate,nsmanagedobject,relationships
The Batting.team relationship doesn't always save properly and returns null sometimes About 100 'Team' NSManagedObjects are saved and can log their attributes as expected. Then about 15000 'Batting' NSManagedObjects are saved and all attributes log correctly except for the relationship. I want the Batting.team relationship to point to the Team...

Optional relationship in SQL Server — How to implement in SSMS Schema Designer


sql-server,ssms,database-schema,relationships,table-relationships
I have two cases where I would like to set 'optional' relationship inside one table or between two tables. First: I want to set this relation as optional, in other words: there will be categories and subcategories in one table, so subcategory column is only optional. Second: Here I want...

Best way of protecting the show() method against users accessing other users messages


laravel,laravel-4,routing,models,relationships
Ok, so I have a basic messaging system, I have a relationship set up so I can just call $user->messages to retrieve an array of the users inbox messages. I also have a very simple show method that currently only grabs the message with id passed to the show() function....

Loopback - GET model using custom String ID from MongoDB


database,mongodb,model,loopbackjs
I'm developing an API with loopback, everything worked fine until I decided to change the ids of my documents in the database. Now I don't want them to be auto generated. Now that I'm setting the Id myself. I get an "Unknown id" 404, whenever I hit this endpoint: GET...

What's the difference between embedsMany and hasMany in Strongloop loopback


relationships,loopbackjs
At first sight they seem to do the same thing: define a one-to-many relation So why would you choose one or another?

StrongLoop: EmbedsMany vs hasMany and belongTo


javascript,mysql,loopbackjs,strongloop
My App has this Events Models. If I create another Model: Dates... so an Event can have multiple Dates, should I use Events EmbedsMany Dates? or is better to use Events hasMany Dates and Dates belongsTo Event? What's the difference? New Dates to the event might be added later after...

strongloop slc deploy env var complications


deployment,loopbackjs,strongloop
I've been deploying a loopback app via a custom init.d/app.conf script, using slc run --detach --cluster "cpu", but want to move to using strong-pm, as recommended. But I've come across some limitations and am looking for any guidance on how to replicate the setup with which I'm currently familiar. Currently...

How to implement the class - Student relationship in c#? [closed]


c#,class,model-associations,relationships
I want to implement a system, which represents a ClassRoom- Student relationship. I want to impose the constraint that Each ClassRoom can have any number of students, but one student can be at only one ClassRoom. I have created two classes - ClassRoom and Student. I have created a list...

Best Practice For Consistent REST Status On Success/Failure (Using LoopBack)


loopbackjs
We're using LoopBack (by StrongLoop) for our REST framework. What is the best practice for determining success or failure? A successful result simply returns the the data (in JSON). An unsuccessful result returns readyState, responseText, status and statusText. It would be really nice if the successful result also returned a...

How do I create a correct hasOne relation between two objects with loopback and angular


angularjs,mongodb,loopbackjs
I've recently started to code in angular as the frontend code and was planning to use loopback (www.loopback.io) as my backend (with a mongodb for my storage). Now, as a basic idea I'm just creating a login form and register form and will go on from there. Yet, I can't...

Add multiple dir for static files in Loopback


loopbackjs
Loopback has two areas where paths are set for static files: server.js var path = require('path'); app.use(loopback.static(path.resolve(__dirname, '../client'))); middleware.json "files": { "loopback#static": { "params": "$!../client" } }, In my dev environment I'd also like to reference another dir for example /node_modules How do I do this?...

Migrating built-in models to Databases


loopbackjs,strongloop
How to move built-in models like User, Roles, User-Role-Mapping etc... to the database we've created instead of the default datasource:db? The built-in models are not listing in Arc. I've tried creating a new model which inherits these base model. But, data is not saved into the new model. Please advice...I've...

Log in user with one-time token using Loopback


javascript,authentication,access-token,loopbackjs
I'm working on a Loopback application that has two types of users — a "Supervisor" that can self-register within the app and a "Subordinate" that can only be registered by Supervisors (and is tied to that person). Supervisors use an email and password to log in like the base User...

Entity Framework (Code First) One to Many and One to One relations (with two entities). How to?


entity-framework,one-to-many,code-first,one-to-one,relationships
I'm trying to do this with EF Code First: There area two tables: Users and Areas. One User belongs to one required area and one Area can have zero or one User (as administrator). Then: Users *..1 Areas and Users 0..1 Areas The Users class: public class User { public...

Strongloop Loopback: Filter by id of related Model


javascript,angularjs,node.js,loopbackjs,strongloop
I have a Strongloop Loopback Node.js project with some models and relations. The problem at hand My problem relates how to query only those Media instances that have a relation to a certain Tag id, using the Angular SDK - while not querying Tags.media (which return Tag instances), but instead...

How log an HTTP JSON request in Loopback app deployed on Heroku?


node.js,logging,heroku,express,loopbackjs
An app (Loopback) is deployed on Heroku, and I need to to see the req body (the JSON) send to this app for debugging purpose. So the access to the log is : heroku logs --tail The server.js is like the following : var loopback = require('loopback'); var boot =...

Loopback: Cannot find module 'negotiator'


database,node.js,loopbackjs
I'm trying to use Loopback to create an api for my existing database. When I try to 'discover' the model, I get this error: Message: Cannot find module 'negotiator' Request: /workspace/api/DataSourceDefinitions/server.tweetvtds/testConnection Staus: 500 Error: Cannot find module 'negotiator' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17)...

Amazon S3 browser direct upload unique file name


angularjs,node.js,amazon-s3,loopbackjs
I'm using Node.js and the Amazon aws sdk for signing an upload request so I can do direct uploads from an Angular application. It works really well except I can't get unique file names. I have tried with creating unique buckets instead but then I can't get the CORS settings...

Trouble setting up a Loopback production host on AWS EC2


amazon-web-services,amazon-ec2,permissions,loopbackjs,strongloop
I'm having trouble setting up a StrongLoop LoopBack production host on AWS EC2. I'm following these directions. This is what I tried. I created an EC2 server that's a Ubuntu Server 14.04 LTS. Then I: $ ssh -i ~/mykey.pem [email protected][ec2-ip-address] $ sudo apt-get update $ sudo apt-get install build-essential $...

Hide LoopBack PUT REST API method


node.js,loopbackjs,strongloop
How do I hide the PUT REST API method in LoopBack? I've been able to successfully hide many other methods, but not the PUT method. > $ slc -v strongloop v2.10.3 (node v0.10.35) ├── [email protected] ├── [email protected] (5a43a57) ├─┬ [email protected] (c945bd1) │ └── [email protected] ├── [email protected] ├── [email protected] (5e25e21) ├──...

StrongLoop: mutual Model Relations


javascript,loopbackjs,strongloop,loopback
I have this app with 3 Models: Users, Events and Venues. An user can create events that take places in a venue, This are the relations: User: hasMany Event Venue: hasMany Event Event: belongsTo User But I'm not sure if Event must also belongsTo Venue? (as the Venue is not...

How can I use body-parser with LoopBack?


node.js,express,middleware,loopbackjs,body-parser
I see that LoopBack has the Express 3.x middleware built-in. Indeed, body-parser is in loopback/node_modules. But I cannot figure out how to use it as middleware. I have never worked with Express 3.x, so maybe it's just that. require does not work, obviously, unless I install body-parser as a dependency...

How to create a NodeJS + LoopBack Application using WebStorm?


node.js,webstorm,loopbackjs
I am using WebStorm v 9.0.3. I would like to create a Strongloop/Loopback Application + NodeJS Application. Is there a way to create it directly through WebStorm IDE or should we manually do it using commandline. Currently I can see only NodeJS Express App provision during project creation in WebStorm....

Loopback passport mobile login


facebook,mobile,passport.js,loopbackjs
I'm developing an API with loopback and passport. I've seen this example, which is quite good: https://github.com/strongloop/loopback-example-passport In the documentation, they say loopback follows this step to authenticate users via third party providers: A visitor requests to log in using Facebook by clicking on a link or button backed by...

Core Data properties based upon relationships returning NULL


core-data,nspredicate,nsmanagedobject,nsmanagedobjectcontext,relationships
I have a Core Data data model such as I want to display the Teams.name associated with each Batting object in my UITableViewCell. When I try to access batting.teams.name it returns NULL. My opening view controller has a string passed in then creates a new viewController with NSPredicate based from...

Laravel ORM nested relationships with constraints


laravel-4,nested,relationships
I'm wondering how to perform a nested relationship query with constraints in Laravel 4.1. Here is a reference query which works: $users = User::with("careers.specialty.faculty.university")->get(); As you can see, there are several nested models (with various relation types). I would like to load an optional constraint to one or several models,...

LoopBack installation failed with error code “ECONNRESET”


node.js,loopbackjs
I wanted follow this tutorial and one of the first steps - the installation of LoopBack failed. The type npm-debug.log tells: 41099 error argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "strongloop" 41100 error node v0.12.2 41101 error npm v2.7.4 41102 error code ECONNRESET 41103 error errno ECONNRESET 41104 error syscall...

Cannot connect to StrongLoop PM using StrongLoop Arc


node.js,loopbackjs,strongloop
I'm having trouble connecting to StongLoop PM using StrongLoop Arc. I'm following these directions. Here's what I tried: # in one terminal window, I started up StrongLoop PM $ nvm install v0.12.4 $ nvm alias default 0.12.4 $ npm install -g strongloop $ slc loopback > name: hello-strongloop > directory:...

Can association lines be merged in one line in UML?


uml,software-design,class-diagram,relationships
Is it in accordance with the UML standard to merge a few association lines into one line, like on the attached diagram? ...

ACL on certain records instead of API URLs


loopbackjs,strongloop,loopback
I'm stuck with a scenario where a logged in user can create blog posts in a CMS like system. So he creates these posts in a backend system. When that user is on the Blog page in the admin panel in then an API request like this is sent: /api/blogs?filter={'userid':...

Createmany in Strongloop Loopback


loopbackjs,strongloop
I have an Order model which hasMany OrderItem models. But once a client wants to create an Order, it has to create an Order object first then for each product he added to his basket, he needs to create responding OrderItems separately. As you may notice it causes many reduntant...

Verification code rather than url in loopback


node.js,loopbackjs
I am using Loopback as an api for a phone app. How could I change the out of the box verification of an email address when a user signs up. I need it to be a 4 digit code (instead of a url) so that it's more friendly to the...

Database Model to Represent Families, Households, and Relationships


database,model,relationships
Here's my situation. I am building a database to track relationships between people and households. Typically, everything is tied to a "head of household". I am trying to avoid this as it creates problems when people move (i.e. brother finally gets a job and moves out) or families break up...

Implementing Q with Strongloop Loopback


javascript,node.js,promise,q,loopbackjs
Q is a "supporting module" of loopback. I'm not totally sure what that means, but I'm assuming that it at least means that is possible to use Q with loopback's Persistent Model functions, like find() or findOne(). I'd like to know how to properly setup something like the following: app.models.Question.findOne({...

StrongLoop Framework - Access-Control-Allow-Origin: *


angularjs,node.js,rest,loopbackjs,strongloop
I have an AngularJS / Strongloop project. The AngularJS part of the code is not hosted at the same location as the Strongloop project and as a result I'm running into a CORS issue. I have done a lot of reading on this issue, however I can't figure out how...

Can I get to response headers in Loopback afterRemote hook?


express,loopbackjs,strongloop,keen-io
I have a Loopback model on which I am logging requests to keen.io using the afterRemote hook. http://docs.strongloop.com/display/public/LB/Remote+hooks#Remotehooks-ctx.result I am also using the response-time package to add the response time header to the response. https://github.com/expressjs/response-time This is working fine, expect I cannot figure out how to get to the X-Response-Time...