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

Bulk property assignment #699

Closed
benmajor opened this issue Feb 25, 2019 · 3 comments
Closed

Bulk property assignment #699

benmajor opened this issue Feb 25, 2019 · 3 comments

Comments

@benmajor
Copy link
Contributor

Is there any chance of adding something like the following to the roadmap? It would certainly be helpful in lots of instances (not least of which is importing existing data or CSVs, or similar):

$book = R::dispense('book', [
    'name'   => 'The Jabberwocky',
    'author' => 'Carroll, Lewis',
    'year'   => 2009
]);
@Lynesth
Copy link
Collaborator

Lynesth commented Feb 25, 2019

Hey there,

How is that different from R::import or this ?

$book = R::dispense( [
        '_type' => 'book',
        'title'  => 'Gifted Programmers',
        'author' => [ '_type' => 'author', 'name' => 'Xavier' ],
        'ownPageList' => [ ['_type'=>'page', 'text' => '...'] ]
    ] );

@benmajor
Copy link
Contributor Author

Hmm, good point!

@Lynesth
Copy link
Collaborator

Lynesth commented Feb 25, 2019

@benmajor Just to add that you could also use R::convertToBeans with your own array (instead of database's rows)

    /**
     * Converts a series of rows to beans.
     * This method converts a series of rows to beans.
     * The type of the desired output beans can be specified in the
     * first parameter. The second parameter is meant for the database
     * result rows.
     *
     * Usage:
     *
     * <code>
     * $rows = R::getAll( 'SELECT * FROM ...' )
     * $beans = R::convertToBeans( $rows );
     * </code>
     *
     * As of version 4.3.2 you can specify a meta-mask.
     * Data from columns with names starting with the value specified in the mask
     * will be transferred to the meta section of a bean (under data.bundle).
     *
     * <code>
     * $rows = R::getAll( 'SELECT FROM... COUNT(*) AS extra_count ...' );
     * $beans = R::convertToBeans( $rows );
     * $bean = reset( $beans );
     * $data = $bean->getMeta( 'data.bundle' );
     * $extra_count = $data['extra_count'];
     * </code>
     *
     * New in 4.3.2: meta mask. The meta mask is a special mask to send
     * data from raw result rows to the meta store of the bean. This is
     * useful for bundling additional information with custom queries.
     * Values of every column whos name starts with $mask will be
     * transferred to the meta section of the bean under key 'data.bundle'.
     *
     * @param string $type     type of beans to produce
     * @param array  $rows     must contain an array of array
     * @param string $metamask meta mask to apply (optional)
     *
     * @return array
     */
    public static function convertToBeans( $type, $rows, $metamask = NULL )

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

2 participants