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

Usage about the getRawAttributes() in ModelInterface #56

Open
dreamsbond opened this issue Jan 18, 2019 · 3 comments
Open

Usage about the getRawAttributes() in ModelInterface #56

dreamsbond opened this issue Jan 18, 2019 · 3 comments
Assignees
Labels

Comments

@dreamsbond
Copy link

Curious if the getRawAttributes() can be used for storing spatial data type.

@neomerx
Copy link
Collaborator

neomerx commented Jan 19, 2019

I think you can. Any type that Doctrine can work with can be used. On their web site, I've found how to make spatial types in Doctrine.

The type I use \Limoncello\Flute\Types\DateTimeType is another example of how to make custom Doctrine type.

@neomerx neomerx self-assigned this Jan 19, 2019
@dreamsbond
Copy link
Author

could you give some examples of using GetRawAttributes()?

@neomerx
Copy link
Collaborator

neomerx commented Jan 21, 2019

The spatial types example should be used as a normal type (e.g. Type::INTEGER, Type::STRING or DateTimeType::NAME).

Row Attributes are simply added to SELECT when data are read from a database without any changes. I use them to call various functions and add columns with their results. For example, if I have a column that links to some user, I can add an extra column that would have user's name

    /**
     * @inheritdoc
     */
    public static function getRawAttributes(): array
    {
        return [

                [self::class, 'getRawAttributeFullName'],

            ] + parent::getRawAttributes();
    }

    /**
     * Called to add an extra column in SELECT statements.
     *
     * @param ModelQueryBuilder $builder
     *
     * @return string
     */
    public static function getRawAttributeFullName(ModelQueryBuilder $builder): string
    {
        $function   = UserFullNameFunctionMigration::FUNCTION_NAME;
        $userId     = $builder->getQuotedMainAliasColumn(self::FIELD_ID_USER);
        $columnName = self::V_FIELD_AUTHOR_FULL_NAME;

        return "$function($userId) AS $columnName";
    }

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

No branches or pull requests

2 participants