Skip to content
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

Relation with property path ** in entity was not found #15

Open
woobottle opened this issue Jun 22, 2021 · 3 comments
Open

Relation with property path ** in entity was not found #15

woobottle opened this issue Jun 22, 2021 · 3 comments

Comments

@woobottle
Copy link

woobottle commented Jun 22, 2021

Paragraphs.entity.ts

import {
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  Entity,
  JoinColumn,
  OneToMany,
  JoinTable,
} from 'typeorm';
import { DateAudit } from '@entities/date-audit.entity';
import { Posts as Post } from '@posts/posts.entity';
import { Likes as Like } from '@likes/likes.entity';
import { Comments as Comment } from '@comments/comments.entity';
import { PolymorphicChildren } from 'typeorm-polymorphic';

@Entity()
export class Paragraphs extends DateAudit {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  body: string;

  @Column({
    default: 0,
  })
  viewCount: number;

  @ManyToOne(() => Post, (post) => post.paragraphs)
  @JoinColumn({ name: 'post_id' })
  post: Post;

  @OneToMany(() => Comment, (comment) => comment.paragraph)
  comments: Comment[];

  @PolymorphicChildren(() => Like, { eager: true })
  likes: Like[];
}

likes.entity.ts

import { Column, ManyToOne, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { DateAudit } from '@entities/date-audit.entity';
import { Paragraphs as Paragraph } from '@paragraphs/paragraphs.entity';
import { PolymorphicChildInterface } from 'typeorm-polymorphic/dist/polymorphic.interface';
import { PolymorphicParent } from 'typeorm-polymorphic';

@Entity()
export class Likes extends DateAudit implements PolymorphicChildInterface {
  @PrimaryGeneratedColumn()
  id: number;

  @PolymorphicParent(() => [Paragraph], { eager: false })
  owner: Paragraph;

  @Column({ name: 'entity_id', nullable: true, type: 'int' })
  entityId: number;

  @Column({ name: 'entity_type', nullable: true })
  entityType: string;
}

posts.entity.ts

import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { DateAudit } from '@entities/date-audit.entity';
import { Presses as Press } from '@presses/presses.entity';
import { Paragraphs as Paragraph } from '@paragraphs/paragraphs.entity';
import { Categories as Category } from '@categories/categories.entity';

@Entity()
export class Posts extends DateAudit {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: true })
  title: string;

  @ManyToOne(() => Press, (press) => press.posts)
  @JoinColumn({ name: 'press_id' })
  press: Press;

  @Column({ nullable: true })
  image: string;

  @OneToMany(() => Paragraph, (paragraph) => paragraph.post)
  paragraphs: Paragraph[];

  @ManyToOne(() => Category, (category) => category.posts)
  @JoinColumn({ name: 'category_id' })
  category: Category;
}

posts.repository.ts

import {
  getConnection,
  EntityRepository,
  In,
  Repository,
  getRepository,
} from 'typeorm';
import { Likes as Like } from '@likes/likes.entity';
import { Comments as Comment } from '@comments/comments.entity';
import { Paragraphs as Paragraph } from '@paragraphs/paragraphs.entity';
import { AbstractPolymorphicRepository } from 'typeorm-polymorphic';
import { Posts as Post } from './posts.entity';

@EntityRepository(Post)
export class PostsRepository extends AbstractPolymorphicRepository<Post> {
  async findById(id: number): Promise<Post> {
    const post = await getRepository(Post)
      .createQueryBuilder('post')
      .leftJoinAndSelect('post.paragraphs', 'paragraphs')
      .innerJoinAndSelect('paragraphs.comments', 'comments')
      .leftJoinAndSelect(
        'paragraphs.likes',
        'likes',
      )
      .where('post.id = :id', { id })
      .getOne();
    return post;
  }
}

i want use 'paragraphs.likes' in PostsRepository
but it always return [ExceptionsHandler] Relation with property path likes in entity was not found.
plz help me i want use this

@wonderlandzor
Copy link

i want use 'paragraphs.likes' in PostsRepository
but it always return [ExceptionsHandler] Relation with property path likes in entity was not found.
plz help me i want use this

assumption: you need to define the relationship on the Posts end, or define an inverse relationship. I've been trying to figure out related things lately. I'm not 100% sure if this library actually works as intended, I'm looking into seeing if I can PR something or actually misunderstand.

@woobottle
Copy link
Author

assumption: you need to define the relationship on the Posts end, or define an inverse relationship. I've been trying to figure out related things lately. I'm not 100% sure if this library actually works as intended, I'm looking into seeing if I can PR something or actually misunderstand.

if you find something useful thing
please notice that
thanks for your reply

also i will find to solve this

@shathaabualrob
Copy link

Did u manage to find any solution for this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants