Code Monkey home page Code Monkey logo

Comments (7)

jucasoft avatar jucasoft commented on September 29, 2024 1

Resolved

from ngrx-entity-relationship.

satanTime avatar satanTime commented on September 29, 2024

Hi again,

might you explain how you tried to search for it? I'll try to add suitable keywords to improve search appearance.

There are several options:

  1. company should provide staffId.
export interface Company {
    id: string;
    name: string;

    staffId?: Array<string>; // and array of ids to select
    staff?: Array<User>;

    admin?: User;
    adminId?: string;

    address?: Address;
    addressId?: string;
}

const companyWithEmployees = rootEntity(
    companySelector,
    relatedEntity( // relatedEntity supports single ids and arrays of them.
        userSelector,
        'staffId',
        'staff',
    ),
);
  1. user has companyId
export interface User {
    companyId?: string;
}

const companyWithEmployees = rootEntity(
    companySelector,
    childEntity( // childEntity searches for suitable users based on companyId == company.id.
        userSelector,
        'companyId',
        'staff',
    ),
);

For many to many - might you provide your data structure and how you would like to select the records?
In my case I used typeorm and for such relationships it returns data like staffId.

from ngrx-entity-relationship.

jucasoft avatar jucasoft commented on September 29, 2024

I found you looking for the words "ngrx entity one to many":
https://stackoverflow.com/questions/61933118/ngrx-how-to-many-to-many-relationship-between-entities

I've been looking for weeks:
normalizing
https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape
https://github.com/paularmstrong/normalizr

ngrx orm
https://gist.github.com/musou1500/6f7649bf230f1c7e06280b0103519b8b

from ngrx-entity-relationship.

satanTime avatar satanTime commented on September 29, 2024

Aha, thanks.

I'll try to promote "ngrx orm" and "ngrx normalizing". For the last weeks I've been working on redux version, because of that, I think, the next update will be ready only in 2-3 weeks.

Btw, does the thing about many-to-many work for you?

from ngrx-entity-relationship.

jucasoft avatar jucasoft commented on September 29, 2024

hi,

Hi, I tried the implementation, but I have an error.

companyId successfully finds it in the User entity
https://github.com/jucasoft/ngrx-entity-crud-prime-ng-boilerplate/blob/a8e3103ef42d063c832d04e190de45c9dc629f79/src/app/main/models/vo/user.ts#L8

staff, does not find it in Compani (even if present) it seems to look for it in User.
https://github.com/jucasoft/ngrx-entity-crud-prime-ng-boilerplate/blob/a8e3103ef42d063c832d04e190de45c9dc629f79/src/app/root-store/company-store/selectors.ts#L29

from ngrx-entity-relationship.

satanTime avatar satanTime commented on September 29, 2024

Yeah, my bad. Because it's an array not childEntity, but childrenEntity should be used.

const companyWithEmployees = rootEntity(
  selectState,
  childrenEntities(
    UserStoreSelectors.selectState,
    'companyId',
    'staff',
  ),
);

from ngrx-entity-relationship.

satanTime avatar satanTime commented on September 29, 2024

another thing is that with the current approach it causes Warning: Circular dependency detected:.
It's quite common because of cross relationships.

it's caused by

export const selectState: MemoizedSelector<object, State> = createFeatureSelector<State>(Names.NAME);

and

export const selectState: MemoizedSelector<object, State> = createFeatureSelector<State>(Names.NAME);

it should be in any other file, but not within ngrx-entity-relationship selectors.
I put them in the state.ts usually.

then it's like that: https://take.ms/nLoxh

I've created a PR: jucasoft/ngrx-entity-crud-prime-ng-boilerplate#1

from ngrx-entity-relationship.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.