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

Idea: allow syntax -- new Article ( $initial_data ) #19

Closed
yespire opened this issue Apr 25, 2016 · 3 comments
Closed

Idea: allow syntax -- new Article ( $initial_data ) #19

yespire opened this issue Apr 25, 2016 · 3 comments

Comments

@yespire
Copy link
Contributor

yespire commented Apr 25, 2016

@pmjones @harikt

Is it possible to have the following syntax:

$new_article = new Article( $initial_data );
$atlas->persist( $new_article );

Sure, it can be done like:

$new_article = $atlas->newRecord(\PathTo\ArticleMapper, $initial_data);
$atlas->create($new_article)

But the former would be a lot easier to read.

This idea is conflicting with current Record API
`Record :: __constructor(mapperClassName, $row, $related)

But we can probably achieve this via a small change:

Record :: __constructor($row_or_data, array $related = [], $mappeClassName = NULL);
-- if $row_or_data is not instance of ROW, new row($data)
-- we can generate the mapperClassName when provided NULL
-- this has only impact on "newRecord()" case, because existing record is acquired via "fetchRecord"

@pmjones
Copy link
Contributor

pmjones commented Apr 27, 2016

My guess is this means the Row classes will have to be customized for each table, with the table columns names being populated into the custom classes somehow. Otherwise the Row has no way of knowing what its column names are. (I am not opposed to that.) So if you want to send a PR to that effect, probably including a PR to Atlas.Cli, I'd be happy to review it.

@yespire
Copy link
Contributor Author

yespire commented Apr 27, 2016

I am not sure I get what you mean by Row Classes will have to be customized for each table, I am currently under impression that row doesn't need to be touched for this change

I notice the class/file naming are very predictable in Datasource folder
Therefore the MapperClass name can be calculated according to current record object when user is using: new ArticleRecord() syntax

@yespire
Copy link
Contributor Author

yespire commented May 4, 2016

My understanding changed:
"new Article()" syntax is not a good idea and unncessary
produce new object via factory method or class is better in general

@yespire yespire closed this as completed May 4, 2016
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