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

pkp/pkp-lib#10133 Port Genre and GenreDAO to Use Eloquent Model #10194

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Hafsa-Naeem
Copy link
Contributor

for #10133

@CLAassistant
Copy link

CLAassistant commented Jul 12, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@asmecher asmecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Hafsa-Naeem, I've added some comments but I think the biggest thing is to agree on some conventions WRT the settings table and collectors -- feel free to clean up some details, then let's make sure we've got those conventions figured out before continuing!

// Relationships
public function submissionFiles(): HasMany
{
return $this->hasMany(SubmissionFile::class, 'genre_id');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this should be genre_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this relationship definition because in the database schema, genre_id is used as the foreign key in submission_files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I misread this, thanks!

// Accessors and Mutators
protected function entryKey(): Attribute
{
return Attribute::make(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an equivalent to this in the previous implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous implementation we used getter and setter methods for entryKey

public function getKey()
{
    return $this->getData('key');
}

public function setKey($key)
{
    $this->setData('key', $key);
}

and in the new Eloquent this is replaced with

    protected function entryKey(): Attribute
    {
        return Attribute::make(
            get: fn($value) => strtoupper($value),
            set: fn($value) => strtolower($value)
        );
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the uppercase/lowercase conversion I was wondering about; if it didn't exist in the previous code, best not to add it here.

);
}

protected function enabled(): Attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're just looking to cast a PHP boolean into a database int...

  • It might be better to use attribute casting, or
  • better still, just leave it an integer and at some point we'll declare boolean columns in the DB with the boolean type so that everything matches nicely without needing casting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this class still be required after the move to Eloquent is completed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asmecher No. it's temporary until the settings table handling is sorted out.

/**
* Get enabled genres by context ID.
*
* @param int $contextId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param phpdocs don't add anything that's not already in the function declaration, so please remove them. (Here and below.)

}

return $query->get();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a blank space between function declarations.

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

Successfully merging this pull request may close these issues.

3 participants