-
Hello, Community! I'm currently working on the laravel-cycle-orm-adapter project, aiming to integrate laravel/telescope with native Cycle ORM migrations. I've encountered a challenge while attempting to adapt Laravel Telescope's migration files for use with Cycle ORM, specifically regarding the #[ForeignKey] annotation. Original Laravel Telescope Migration FileI started with the Laravel Telescope migration file located here: https://github.com/laravel/telescope/blob/5.x/database/migrations/2018_08_08_100000_create_telescope_entries_table.php 2018_08_08_100000_create_telescope_entries_table.php
Which generates such SQL: CREATE TABLE "telescope_entries" (
"sequence" integer primary key autoincrement not null,
"uuid" varchar not null,
"batch_id" varchar not null,
"family_hash" varchar,
"should_display_on_index" tinyint(1) not null default '1',
"type" varchar not null,
"content" text not null,
"created_at" datetime);
CREATE TABLE "telescope_entries_tags" (
"entry_uuid" varchar not null,
"tag" varchar not null,
foreign key("entry_uuid") references "telescope_entries"("uuid") on delete cascade,
primary key ("entry_uuid", "tag"));
CREATE TABLE "telescope_monitoring" (
"tag" varchar not null,
primary key ("tag"));
INSERT INTO "telescope_entries" ("sequence", "uuid", "batch_id", "family_hash", "should_display_on_index", "type", "content", "created_at") VALUES
('1', '9b9e8cb0-40d7-4146-b2fe-aed5b6e9a5a9', '9b9e8cb0-4b76-4bff-8130-cc526872d3fd', NULL, '1', 'query', '{"connection":"sqlite","bindings":[],"sql":"select exists (select 1 from pragma_compile_options where compile_options = ''ENABLE_DBSTAT_VTAB'') as enabled","time":"0.20","slow":false,"file":"\/github\/wayofdev\/_playground\/example-laravel-app\/artisan","line":13,"hash":"bbe479d6d8ae419144ed7d668fb48ce2","hostname":"ghosts-MacBook-Pro.local"}', '2024-03-21 20:24:34');
This file contains the schema for creating Converted ORM EntitiesFrom the Laravel migration file, I've created the following annotated ORM entities: For <?php
declare(strict_types=1);
namespace WayOfDev\Cycle\Bridge\Telescope\Entities;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Table\Index;
use DateTimeImmutable;
#[Index(columns: ['batch_id'])]
#[Index(columns: ['family_hash'])]
#[Index(columns: ['created_at'])]
#[Index(columns: ['type', 'should_display_on_index'])]
#[Entity(table: 'telescope_entries')]
class TelescopeEntry
{
#[Column(type: 'bigInteger', primary: true)]
public int $sequence;
#[Column(type: 'uuid', unique: true)]
public string $uuid;
#[Column(type: 'uuid')]
public string $batchId;
#[Column(type: 'string', nullable: true)]
public string $familyHash;
#[Column(type: 'boolean', default: true)]
public bool $shouldDisplayOnIndex;
#[Column(type: 'string', size: 20)]
public string $type;
#[Column(type: 'longText')]
public string $content;
#[Column(type: 'datetime', nullable: true)]
public ?DateTimeImmutable $createdAt;
} For <?php
declare(strict_types=1);
namespace WayOfDev\Cycle\Bridge\Telescope\Entities;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\ForeignKey;
use Cycle\Annotated\Annotation\Table\Index;
#[Index(columns: ['entry_uuid', 'tag'])]
#[Index(columns: ['tag'])]
#[ForeignKey(target: 'telescope_entries', innerKey: 'entry_uuid', outerKey: 'uuid', action: 'CASCADE')]
#[Entity(table: 'telescope_entries_tags')]
class TelescopeEntryTags
{
#[Column(type: 'uuid')]
public string $entryUuid;
#[Column(type: 'string')]
public string $tag;
} For <?php
declare(strict_types=1);
namespace WayOfDev\Cycle\Bridge\Telescope\Entities;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
#[Entity(table: 'telescope_monitoring')]
class TelescopeMonitoring
{
#[Column(type: 'string', primary: true)]
public string $tag;
} Issue with
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Update: Found my issue, had to define target as FQDN class-name:
Current workaround: Is to define property and add HasMany annotation to it: <?php
declare(strict_types=1);
namespace WayOfDev\Cycle\Bridge\Telescope\Entities;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\ForeignKey;
use Cycle\Annotated\Annotation\Relation\HasMany;
use Cycle\Annotated\Annotation\Table\Index;
use Illuminate\Support\Collection;
#[Index(columns: ['entry_uuid', 'tag'])]
#[Index(columns: ['tag'])]
// #[ForeignKey(target: 'telescope_entries', innerKey: 'entry_uuid', outerKey: 'uuid', action: 'CASCADE')]
#[Entity(table: 'telescope_entry_tags')]
class TelescopeEntryTags
{
#[Column(type: 'uuid', primary: true)]
public string $entryUuid;
#[Column(type: 'string')]
public string $tag;
#[HasMany(target: TelescopeEntry::class, innerKey: 'entry_uuid', outerKey: 'uuid', fkAction: 'CASCADE')]
public Collection $entries;
} |
Beta Was this translation helpful? Give feedback.
Update: Found my issue, had to define target as FQDN class-name:
Current workaround:
Is to define property and add HasMany annotation to it: