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

oil refine fromdb:scaffold --all #253

Open
stvowi opened this issue May 13, 2017 · 3 comments
Open

oil refine fromdb:scaffold --all #253

stvowi opened this issue May 13, 2017 · 3 comments

Comments

@stvowi
Copy link

stvowi commented May 13, 2017

...don't work. I tested with WAMP server and PHP 5.6 and Fuel 1.9 dev

I got an exception in scaffold.php Line 63: array to string conversersion.

I fixed it with...

		foreach (array_slice($args, 1) as $arg)
		{
			if (is_string($arg))
			{
				// Parse the argument for each field in a pattern of name:type[constraint]
				preg_match(static::$fields_regex, $arg, $matches);

				if ( ! isset($matches[1]))
				{
					throw new Exception('Unable to determine the field definition for "'.$arg.'". Ensure they are name:type');
				}

				$data['fields'][] = array(
					'name'       => \Str::lower($matches[1]),
					'type'       => isset($matches[2]) ? $matches[2] : 'string',
					'constraint' => isset($matches[4]) ? $matches[4] : null,
				);				
			}
			else
			{
				$data['fields'][] = array(
					'name'       => \Str::lower($arg['name']),
					'type'       => $arg['type'],
					'constraint' => $arg['constraint'],
				);
			} 			
		}

and than I got a new exception in generate.php (line 2040)....GlobIterator throws LogicException
There is a Problem with the GlobIterator. (see: https://bugs.php.net/bug.php?id=55701)

@WanWizard
Copy link
Member

The Globiterator issue was fixed in 5.6, so this suggests your installation isn't up to date (current version is 5.6.30).

@stvowi
Copy link
Author

stvowi commented May 15, 2017

I thought, Fuel PHP needs only PHP 5.3.0 .

Okay, than we come to the next problem.

There will generated 2 id fields in the model if the database table have the id field.

Sample:

<?php
use Orm\Model;

class Model_Object extends Model
{
	protected static $_properties = array(
		'id',
		'id',
		'label',
		'created_at',
		'updated_at',
	);

	protected static $_observers = array(
		'Orm\Observer_CreatedAt' => array(
			'events' => array('before_insert'),
			'mysql_timestamp' => false,
		),
		'Orm\Observer_UpdatedAt' => array(
			'events' => array('before_save'),
			'mysql_timestamp' => false,
		),
	);

	public static function validate($factory)
	{
		$val = Validation::forge($factory);
		$val->add_field('id', 'Id', 'required|valid_string[numeric]');
		$val->add_field('label', 'Label', 'required|max_length[500]');

		return $val;
	}

}

BTW, why will generated the observer, if I don't have created_at/ updated_at fields not in the database table?

@WanWizard
Copy link
Member

WanWizard commented May 15, 2017

PHP 5.3.3+ to be exact. But that doesn't mean it contains workarounds for PHP bugs for any released version after that.

I'll have a look at where the double "id" fields comes from. Just to check, your table only contains an 'id' field (as int, PK) and a label field (char of some sort)?

@WanWizard WanWizard reopened this May 15, 2017
WanWizard added a commit that referenced this issue Mar 17, 2018
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