Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

[eluser]tdktank59[/eluser]
Hey

So ive got a small issue, that ive noticed before... as well.

When you try and save a single field it runs through the entire validation check and ends up error-ing out on fields that I don't care about at that point.

Is there a way we can either make this only check the passed in fields (best solution in my mind, and since then it only checks what we want it to.) Otherwise a way to define which validations to run for a specific insert.

Because im having an issue where ive got a few fields, for some reason or another a field gets blanked out and I try and update it again and it says cannot update because some other field is required that is blanked out as well.

Thanks.

[eluser]Oblique[/eluser]
ITFK instead of dedicated table in case of one-way advanced relationship

We have User and Freightage. User can either create or carry freightage, depending on his role in system, so User can relate to Freightage either as creator or as carrier, but for User Freightage is just Freightage always, so, may i use itfk instead of table? I tried it like that, didn't work:

Code:
freightage.php:
...
    var $has_one = array
    (
         'creator' => array
        (
           'class'         => 'user',
           'other_field' => 'freightage'
        )
        ,'carrier' => array
        (
           'class'         => 'user',
           'other_field' => 'freightage'
        )
...

Code:
user.php
...
var $has_many = array
    (
        'freightage',
...

gives me:

Quote:DataMapper Error: 'user' is not a valid parent relationship for Freightage. Are your relationships configured correctly?

Looks like relations like this are not met often, so it's not supported. Just want to make sure

[eluser]OverZealous[/eluser]
@Oblique
The error message is correct: your relationship is incorrectly defined. Relationships need to be fully defined on both sides. There is no way for DMZ to know how to assign the User in this context:
Code:
$user->save($frieght);
// OR
$freight->save($user);

That's why you need to fully define the relationship on both sides. If you want two different types of relationships, then you need two different relationships defined on both objects. You can still build a single query from two different relationships, like this:
Code:
$freight = new Freight();
$freight->distinct()->where_related_carrier($user)->or_where_related_creator($user)->get();

Alternatively, have you thought about having a single $has_many<->$has_many relationship and using join fields to define the type of relationship? (See Using Join Fields in the manual).

-------------------------

@tdktank59
Either you are not loading the object before you are saving it, or you are setting individual fields to NULL after loading it. DMZ only checks and saves the columns that have not changed since the last get or save.

-------------------------

General Update:

I have some updates to DMZ started, but I've been sick since last Thursday. If I can get over this, I'll got a new version of DMZ with a lot of performance-oriented changes and improvements out this week or next week.

[eluser]NachoF[/eluser]
Hey Phil,

could you please help me on authorization??
Do you use any of the plugins?? which one specifically?? are they compatible with datamapper?
if you do use one, do you still create the "User" model for datamapper? how about a "Role" model??
Id appreciate your advice on this.

[eluser]OverZealous[/eluser]
@NachoF
DMZ's examples include a fully-functional authentication setup. For me, authorization is application-specific, and I do not use any off-the-shelf libraries for it.

I use a simple User belongs to a Group setup, with each group having a series of flags enabling or disabling functionality. I also extended CI's Session library to provide convenient methods for checking access (e.g., $this->system->can_view('action')).

Sorry I cannot be of more service than that. I tend to write my own tools most of the time, because it's often difficult to shoehorn someone else's code into my app. (Irony intended ;-))

[eluser]PoetaWD[/eluser]
Hey man !

Me again... I have a very simple question... and I am pretty sure you already told me about this.. but... anyway... I will ask:

I have two models, one is 'Car' and the other is 'TypeofCar'

The model Car is related to TypeofCar to tell if the car is FORD, or CHEV etc...

My question is how should the model typeofcar be ? The car should be is has many or in has one ?

Code:
var $has_one = array('typeofcar');    
    var $has_many = array();

Code:
var $has_one = array('car');  <----HERE or    
    var $has_many = array('car');  <----HERE ????

Thanks !

Gabriel

[eluser]NachoF[/eluser]
[quote author="OverZealous" date="1266292071"]@NachoF
DMZ's examples include a fully-functional authentication setup. For me, authorization is application-specific, and I do not use any off-the-shelf libraries for it.

I use a simple User belongs to a Group setup, with each group having a series of flags enabling or disabling functionality. I also extended CI's Session library to provide convenient methods for checking access (e.g., $this->system->can_view('action')).

Sorry I cannot be of more service than that. I tend to write my own tools most of the time, because it's often difficult to shoehorn someone else's code into my app. (Irony intended ;-))[/quote]

So that means that for each method that requires some kind of authorization you have to write authorization logic on it???
somethinf like
Code:
function create_product()
{
if($this->system->can_view('action'))
//continue writing create product logic
else
//redirect()?
}
... I dont think I like that approach.

[eluser]Oblique[/eluser]
@Poetawd, let me answer this.

TypeOfCar definitely has_many Car's since, just think of that - if you want to query all the cars of particular Type and it's related to Car as has_one - what car should dmz return??

[eluser]OverZealous[/eluser]
@Poetawd
Each car has one typeofcar, but each typeofcar has many cars. Therefore, you put typeofcar in Car->has_one, and you put car in TypeOfCar->has_many.

-------------------------

@NachoF
Well, it's not quite that bad. My session method automatically handles returning the error, so it's just this:
Code:
function create_product() {
    $this->session->can_create('product');
    // continue on
}

I don't necessarily recommend my technique for someone else. I needed very fine grained controls (for example, a user might be able to view and edit, but not add or delete a specific item), so there's really no practical way around checking before each controller function. (I also handle other checks, like verifying that the user is logged in, in the controller's constructor.)

I also use extensions to DataMapper to handle a lot of the more general checks (for example, I have methods that process the results of a form, and do the auth checks internally based on $model). My extended DMZ class also handles the authorization lookups on every get, to prevent users from seeing another user's data.

You could probably use CodeIgniter's hooks to handle a more general-purpose authorization technique.

[eluser]someoneinomaha[/eluser]
I'm struggling with modeling a relationship with a project I'm working on.

The models are: band, musician, instrument

Bands have multiple musicians

Musicians have multiple bands and multiple instruments

That's all pretty straightforward, but I also need to keep track of what instruments a musician has for a particular band. So in a sense, I guess, bands have multiple instruments via the musicians.

In the tables, I was going to add instrument_id to the bands_musicians linking table, but I need a musician to be able to have multiple instruments for a band, so I was thinking it would need to go in the musicians_instruments table.

Would anyone have advice on how to model this with DataMapper OverZealous?

Thanks for your time.




Theme © iAndrew 2016 - Forum software by © MyBB