Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]WanWizard[/eluser]
Datamapper uses the CI Form Validation library as well, so using it is not an issue. In fact, quite a few of the Datamapper validation rules, like required, are used from that library.

The error message linked to the Form Validation rules is in the form_validation language file, and loaded by the form validation library. This error means the language string could not be found.


[eluser]animatora[/eluser]
[quote author="WanWizard" date="1339022010"]Datamapper uses the CI Form Validation library as well, so using it is not an issue. In fact, quite a few of the Datamapper validation rules, like required, are used from that library.

The error message linked to the Form Validation rules is in the form_validation language file, and loaded by the form validation library. This error means the language string could not be found.

[/quote]

If I remove the form_validation from autoload.php it is getting the language string. How can I perform validation on non models e.g. I have a login form and I want to validate the data before sending it to my Auth library ? In such cases I am using the CI validation. You are saying DataMapper uses it as well, that is fine, them there is no need for me to load it, how can I access it. When not loaded in the autoload.php it is not finding it.

[eluser]WanWizard[/eluser]
Datamapper does:
Code:
static $CI = NULL;

// get the CI instance
is_null($CI) and $CI =& get_instance();

if( ! isset($CI->form_validation))
{
$CI->load->library('form_validation');
$this->lang->load('form_validation');
}
$this->form_validation =& $CI->form_validation;
Which is how you would do it in any library you would create. No rocket science. Do you also autoload the Datamapper library? Which version of CI? Which version of DM? Bootstrap properly installed?

Are you using some form of HMVC, which could interfere with CI's architecture of having a single instance?

[eluser]animatora[/eluser]
[quote author="WanWizard" date="1339073681"]Datamapper does:
Code:
static $CI = NULL;

// get the CI instance
is_null($CI) and $CI =& get_instance();

if( ! isset($CI->form_validation))
{
$CI->load->library('form_validation');
$this->lang->load('form_validation');
}
$this->form_validation =& $CI->form_validation;
Which is how you would do it in any library you would create. No rocket science. Do you also autoload the Datamapper library? Which version of CI? Which version of DM? Bootstrap properly installed?

Are you using some form of HMVC, which could interfere with CI's architecture of having a single instance?[/quote]

Thanks , as u said it is not a rocket science, I completely forgot that. Sorry for the dummy question. I am using DM 1.8.2, CI 2.1.0 Bootstrap is fine and yes I autoload datamapper


P.S. WanWizard I would like to have your opinion on using annotations in models, when defining class properties:

Code:
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @Column(type="string", length=32, unique=true, nullable=false)
*/
protected $username;

/**
* @Column(type="string", length=64, nullable=false)
*/
protected $password;

/**
* @Column(type="integer", nullable=false)
* @ManyToOne(targetEntity="Groups")
* @JoinColumn(name="user_group", referencedColumnName="id")
*/
protected $user_group;

I know datamapper is not using the annotations, but would it be nice to have them as the project might grow in future and in that way you can keep track on all class properties in use. What is your view on this ?

[eluser]WanWizard[/eluser]
I hate annotations. And I'm not going to implement code that will parse PHP code to figure out what to do. In an ORM, you need every CPU cycle you can find to keep the performance acceptable.

Datamapper is (contrary to what the name implies) based on the active record pattern, in which the code follows the data store. So the data store (in this case the database table) is leading, Datamapper will use it's definition as-is.

If you want a mechanism to document database structure, and have the option to maintain different versions and migrate between them, I can recommend Phil Sturgeon's excellent Migrations library, which does just that.

As to your issue, it looks like something has changed in the form validation library. The language file is now only loaded when form validation is run. Which never happens with Datamapper, it uses it's own method to run rules. So loading the library no longer means the language file is loaded too.

To fix this, look in the Datamapper library for the __get() method. Find in there the section that loads the form validation library, and replace it by this:
Code:
// Special case to get form_validation when first accessed
if($name == 'form_validation')
{
if ( ! isset($this->form_validation) )
{
  isset($CI->form_validation) OR $CI->load->library('form_validation');

  $this->form_validation =& $CI->form_validation;
  $this->lang->load('form_validation');
}

return $this->form_validation;
}
This fix will be part of the next release.

[eluser]animatora[/eluser]
Thank you very much for your answer. I wanted to use annotations just to make programmers live easier, by fast referring to them instead to the database (PHP Doc). I did not mean to implement them as part of DataMapper. Will do what you suggested about the validation later today.and will check Phil Sturgeon’s excellent Migrations, thanks for the tip Smile

[eluser]goddestroyer[/eluser]
Wanwizard...
I'm a huge fan of the datamapper, used it in every project I can for years. I am encountering my first issue that cannot be easily solved be referencing any of the documentation, and i know the solution is just in reach and must be so easy....
I would REALLY APPRECIATE some help with this. Bear with me here, this is going to be a long post, but the real issue here is a simple one, I just have to set up the background info...

summary description:
I know how to include_related join fields, but i simply need a way to alias the same join table twice.


I have a Product model defined as:
Code:
var $has_many = array(..., 'productspecification', ... );


and ProductSpecification model defined as:
Code:
var $has_one = array(...,'product','specification','specificationsection');

The task is to query for a set of products that have two specific relations to ProductSpecifications:
(1) WHERE ProductSpecification.specification = A
AND ProductSpecification.specificationsection = B
AND ProductSpecification.value = X
AND
(2) ProductSpecification.specification = A2
AND ProductSpecification.specificationsection = B
AND ProductSpecification.value = Y


the current code that got me closest is:

Code:
$p->include_related('productspecification', 'value', 'clear_aperture_mm');
  
   $p->group_start();
   $p->where_related_productspecification('specification_id', 19);
   $p->where_related_productspecification('specificationsection_id', 3);
   $p->where_in_related_productspecification('value', $args['clear_aperture_mm']);
   $p->group_end();
  
  
  
  
   $p->include_related('productspecification', 'value', 'magnification_high');
   $p->group_start();
   $p->where_related_productspecification('specification_id', 4);
   $p->where_related_productspecification('specificationsection_id', 3);
   $p->where_in_related_productspecification('value', $args['magnification_high']);
   $p->group_end();


This produces a raw sql query like the following:
Code:
SELECT `products`.*, `productspecifications`.`value` AS clear_aperture_mm_value,
`productspecifications`.`value` AS magnification_high_value
FROM (`products`)
LEFT OUTER JOIN
`productspecifications` productspecifications
ON `products`.`id` = `productspecifications`.`product_id`
LEFT OUTER JOIN `classifications_products`
classifications_products ON `products`.`id` = `classifications_products`.`product_id`
WHERE  
(
`productspecifications`.`specification_id` = 19
AND
`productspecifications`.`specificationsection_id` = 3
AND `productspecifications`.`value` IN (40)

)
AND    (
`productspecifications`.`specification_id` = 4
AND
`productspecifications`.`specificationsection_id` = 3
AND `productspecifications`.`value` IN (0)

  )


Except this will never return results because its asking for both a row that has `productspecifications`.`specification_id` = 19 and at the same time `productspecifications`.`specification_id` = 4.

If i was writing raw sql, this is exactly what i would need:

Code:
SELECT `products`.*, productspecifications1.`value` AS clear_aperture_mm_value,
productspecifications2.`value` AS magnification_high_value
FROM (`products`)
LEFT OUTER JOIN
`productspecifications` productspecifications1
ON `products`.`id` = `productspecifications`.`product_id`
LEFT OUTER JOIN
`productspecifications` productspecifications2
ON `products`.`id` = `productspecifications`.`product_id`
LEFT OUTER JOIN `classifications_products`
classifications_products ON `products`.`id` = `classifications_products`.`product_id`
WHERE  
(
productspecifications1.`specification_id` = 19
AND
productspecifications1.`specificationsection_id` = 3
AND productspecifications1.`value` IN (40)

)
AND    (
productspecifications2.`specification_id` = 4
AND
productspecifications2.`specificationsection_id` = 3
AND productspecifications2.`value` IN (0)

  )


As you can see the only difference is i need each product specification comparison to be its own seperate join, with its own alias. I've read every bit of documentation and spent a good deal of time googling this and i simply can't solve it yet. of course, its for a very large corporate client with deadlines encroaching...

the productspecifications table has columns of: id, product_id, specification_id, specificationsection_id, value, all integers.


please help!
thanks







[eluser]WanWizard[/eluser]
Isn't that the same as
Code:
SELECT `products`.*, `productspecifications`.`value` AS clear_aperture_mm_value,
`productspecifications`.`value` AS magnification_high_value
FROM (`products`)
LEFT OUTER JOIN
`productspecifications` productspecifications
ON `products`.`id` = `productspecifications`.`product_id`
LEFT OUTER JOIN `classifications_products`
classifications_products ON `products`.`id` = `classifications_products`.`product_id`
WHERE  
(
`productspecifications`.`specification_id` = 19
AND
`productspecifications`.`specificationsection_id` = 3
AND `productspecifications`.`value` IN (40)

)
OR    (
`productspecifications`.`specification_id` = 4
AND
`productspecifications`.`specificationsection_id` = 3
AND `productspecifications`.`value` IN (0)

  )

[eluser]goddestroyer[/eluser]
It's not the same. in english, "i need a product that has BOTH of the product specifications: one with specification_id 19, specificationsection_id 3, and value of 40,
AND one with specification_id 4, specificationsection_id 3, and value of 0."

Im only interested in product results that have BOTH of those relations present. I see you have grouped them with an OR, and I too had first written that thinking it was correct, but it is not an OR query that i need-- both of those grouped conditions need to be met, not one or the other. That is normally done with SQL by joining the same table twice, with two different aliases. that is specifically what i cant figure out how to do with datamapper.




[eluser]goddestroyer[/eluser]
thank you immensely for your help, this is one of the only sticky points i've found in years of using the datamapper. this is for a "large important client", but what else is new in our world.




Theme © iAndrew 2016 - Forum software by © MyBB